spatie/mailcoach-sdk-php
PHP SDK for the Mailcoach API (self-hosted v6+ and Mailcoach Cloud). Manage email lists, subscribers, and campaigns: create and send campaigns, send tests, and browse paginated resources with an easy next() workflow.
composer require spatie/mailcoach-sdk-php
.env as MAILCOACH_API_TOKEN, and optionally MAILCOACH_API_URL (defaults to https://mailcoach.app).use Spatie\MailcoachSdk\MailcoachSdk;
$mailcoach = new MailcoachSdk(env('MAILCOACH_API_TOKEN'), env('MAILCOACH_API_URL'));
$mailcoach->subscribers()->create('list-uuid', 'john@example.com', ['name' => 'John Doe']);
Start with subscribers(), lists(), and campaigns() methods — these are the core entry points for most day-to-day operations.
$this->app->singleton(\Spatie\MailcoachSdk\MailcoachSdk::class, function ($app) {
return new \Spatie\MailcoachSdk\MailcoachSdk(
config('services.mailcoach.token'),
config('services.mailcoach.url')
);
});
subscribers()->bulkCreate() or updateMultiple() for high-volume syncs (e.g., after importing users).UserRegistered → subscribe to welcome list).campaigns()->duplicate('uuid'), then monitor status via campaigns()->get('uuid').Mockery or prophecy — its clean interfaces make unit tests fast and reliable.HttpClientException for 4xx/5xx; always wrap critical calls in try/catch or use Laravel’s RateLimiter if sending many requests.request() calls — check MailcoachSdk::request() for fallback.How can I help you explore Laravel packages today?