dsvllc / laravel-sendy
Sendy API implementation for Laravel 8
Installs: 103
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 19
Open Issues: 0
pkg:composer/dsvllc/laravel-sendy
Requires
- php: ^7.3|^8.0
- laravel/framework: ^8.0|^9.0
Requires (Dev)
- phpunit/phpunit: ^8.5|^9.0
README
Laravel Sendy
A service provider for Sendy API in Laravel 9. Much thanks to Jozsef Hocza for the original Laravel 5 version.
Installation
composer require dsvllc/laravel-sendy
or append your composer.json with:
{
"require": {
"dsvllc/laravel-sendy": "^1.*"
}
}
Add the following settings to the config/app.php for the Sendy:: facade
'aliases' => [ // ... 'Sendy' => 'Dsvllc\Sendy\Facades\Sendy', ]
Configuration
php artisan vendor:publish --provider="Dsvllc\Sendy\SendyServiceProvider"
It will create laravel-sendy.php within the config directory.
<?php return [ 'api_key' => env('SENDY_API_KEY', ''), 'list_id' => env('SENDY_LIST_ID', ''), 'installation_url' => env('SENDY_INSTALLATION_URL', ''), ];
Usage
Subscribe:
$data = [ 'email' => 'johndoe@example.com', 'name' => 'John Doe', 'any_custom_column' => 'value', ]; Sendy::subscribe($data);
RESPONSE (array)
In case of success:
['status' => true, 'message' => 'Subscribed'] ['status' => true, 'message' => 'Already subscribed']
In case of error:
['status' => false, 'message' => 'The error message']
Unsubscribe:
$email = 'johndoe@example.com'; Sendy::unsubscribe($email);
RESPONSE (array)
In case of success:
['status' => true, 'message' => 'Unsubscribed']
In case of error:
['status' => false, 'message' => 'The error message']
Subscription status
$email = 'johndoe@example.com'; Sendy::status($email);
RESPONSE (Plain text)
Success:
SubscribedUnsubscribedUnconfirmedBouncedSoft bouncedComplained
Error:
No data passedAPI key not passedInvalid API keyEmail not passedList ID not passedEmail does not exist in list
Active subscriber count
Sendy::count(); #To check other list: Sendy::setListId($list_id)->count();
RESPONSE (Plain text)
Success:
You'll get an integer of the active subscriber count
Error:
No data passedAPI key not passedInvalid API keyList ID not passedList does not exist
Create campaign
<?php $campaignOptions = [ 'from_name' => 'My Name', 'from_email' => 'test@mail.com', 'reply_to' => 'test@mail.com', 'title' => 'My Campaign', 'subject' => 'My Subject', 'list_ids' => '1,2,3', // comma-separated, optional 'brand_id' => 1, 'query_string' => 'utm_source=sendy&utm_medium=email&utm_content=email%20newsletter&utm_campaign=email%20newsletter', ]; $campaignContent = [ 'plain_text' => 'My Campaign', 'html_text' => View::make('mail.my-campaign'), ]; $send = false; Sendy::createCampaign($campaignOptions, $campaignContent, $send);
RESPONSE (Plain text)
Success:
Campaign createdCampaign created and now sending
Error:
No data passedAPI key not passedInvalid API keyFrom name not passedFrom email not passedReply to email not passedSubject not passedHTML not passedList ID(s) not passedOne or more list IDs are invalidList IDs does not belong to a single brandBrand ID not passedUnable to create campaignUnable to create and send campaign
Change list ID
To change the default list ID simply prepend with setListId($list_id) Examples:
Sendy::setListId($list_id)->subscribe($data); Sendy::setListId($list_id)->unsubscribe($email); Sendy::setListId($list_id)->status($email); Sendy::setListId($list_id)->count();
Todo
- Implementing the rest of the API
- More thorough documentation