1. Go to this page and download the library: Download spatie/mailcoach-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / mailcoach-sdk-php example snippets
$mailcoach = new \Spatie\MailcoachSdk\Mailcoach('<api-key>', '<mailcoach-api-endpoint>')
// creating a campaign
$campaign = $mailcoach->createCampaign([
'email_list_uuid' => 'use-a-real-email-list-uuid-here',
'name' => 'My new campaign',
'fields' => [
'title' => 'The title on top of the newsletter',
'content' => '# Welcome to my newsletter',
],
]);
// sending a test of the campaign to the given email address
$campaign->sendTest('[email protected]');
// sending a campaign
$campaign->send();
// listing all subscribers of a list
$subscribers = $mailcoach->emailList('use-a-real-email-list-uuid-here')->subscribers();
do {
foreach($subscribers as $subscriber) {
echo $subscriber->email;
}
} while($subscribers = $subscribers->next())
use Spatie\MailcoachSdk\Mailcoach;
$mailcoach = new Mailcoach('<your-api-key>', '<your-mailcoach-api-endpoint>')
$subscribers = $mailcoach->subscribers('<email-list-uuid');
do {
foreach($subscribers as $subscriber) {
echo $subscriber->email;
}
} while($subscribers = $subscribers->next())
// returns instance of Spatie\MailcoachSdk\Resources\Subscriber
// or null if the subscriber does not exist.
$subscriber = $emaillist->subscriber('[email protected]');
$campaign = $this->createCampaign([
'name' => 'My new campaign',
'subject' => 'Here is some fantastic content for you',
'email_list_uuid' => '<email-list-uuid>',
// optionally, you can specify the uuid of a template
'template_uuid' => '<template-uuid>',
// if that template has field, you can pass the values
// in the `fields` array. If you use the markdown editor,
// we'll automatically handle any passed markdown
'fields' => [
'title' => 'Content for the title place holder',
'content' => '# My title',
],
]);