PHPackages                             spatie/laravel-mailcoach-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. spatie/laravel-mailcoach-sdk

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

spatie/laravel-mailcoach-sdk
============================

An SDK to easily work with the Mailcoach API in Laravel apps

1.5.0(2mo ago)41290.2k—8.1%10[1 PRs](https://github.com/spatie/laravel-mailcoach-sdk/pulls)1MITPHPPHP ^8.3CI passing

Since Nov 8Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/spatie/laravel-mailcoach-sdk)[ Packagist](https://packagist.org/packages/spatie/laravel-mailcoach-sdk)[ Docs](https://github.com/spatie/laravel-mailcoach-sdk)[ RSS](/packages/spatie-laravel-mailcoach-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (20)Versions (13)Used By (1)

An SDK to easily work with the Mailcoach API in Laravel apps
============================================================

[](#an-sdk-to-easily-work-with-the-mailcoach-api-in-laravel-apps)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5a0068043b3fe240f934a6ae436c5ef301cfc5224869271ebb43dcd3e5fc3668/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6d61696c636f6163682d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-mailcoach-sdk)[![GitHub Tests Action Status](https://camo.githubusercontent.com/f11369f269ec311a186d4bf9a2e6b5764ed430e91d8216f631d530e9acc73264/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6d61696c636f6163682d73646b2f72756e2d74657374732e796d6c3f6c6162656c3d7465737473)](https://github.com/spatie/laravel-mailcoach-sdk/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/5075b9cbe0d56e5d2ee782feb7046615ff099409ab9d69559bf2f77560c162af/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6d61696c636f6163682d73646b2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6c6162656c3d636f64652532307374796c65)](https://github.com/spatie/laravel-mailcoach-sdk/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0e21b5e1aa25ff4ce15196f2111f35bcd62916955ac67bacb267ba37e3035344/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6d61696c636f6163682d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-mailcoach-sdk)

This package contains the PHP SDK to work with [Mailcoach](https://mailcoach.app). Both self-hosted (v6 and up) and hosted Mailcoach (aka Mailcoach Cloud) are supported. Using this package you can manage email lists, subscribers and campaigns.

Here are a few examples:

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

// 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('john@example.com');

// sending a campaign
$campaign->send();
```

By default, Mailcoach' endpoints will are paginated with a limit of 1000. The package makes it easy to work with paginated resources. Just call `->next()` to get the next page.

```
// 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())
```

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/0aa3bd65bbf4d8ae6dd0f813fecffac2ddb4106f35f35ee6280949ed12e1209e/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6d61696c636f6163682d73646b2e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-mailcoach-sdk)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-mailcoach-sdk
```

You must publish the config file with:

```
php artisan vendor:publish --tag="mailcoach-sdk-config"
```

This is the contents of the published config file:

```
return [
    /*
     *  You'll find both the API token and endpoint on Mailcoach'
     *  API tokens screen in the Mailcoach settings.
     */
    'api_token' => env('MAILCOACH_API_TOKEN'),

    'endpoint' => env('MAILCOACH_API_ENDPOINT'),
];
```

In your `.env` file you should add the entries from the config file mentioned above. You'll find both the API token and endpoint on Mailcoach' API tokens screen in the Mailcoach settings.

Usage
-----

[](#usage)

You can use the `Spatie\MailcoachSdk\Facades\Mailcoach` facade to perform most operations.

### Handling pagination

[](#handling-pagination)

There are several methods, such as `emailLists()`, 'subscribers()' and `campaigns()` to will return paginated results. To get the next page of results just call `next()` on a result. If there are no more results, that method returns `null`.

Here's how you display the email addresses of every subscriber on a list

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$subscribers = Mailcoach::subscribers('mailcoach->emailList('');
```

This is how you can create an email list:

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

Mailcoach::createEmailList(['name' => 'My new email list']);
```

You can get properties of email list:

```
$emailList->name;
$emailList->uuid;
// ...
```

Take a look at the source code of `Spatie\MailcoachSdk\Resources\EmailList` to see the list of available properties.

You can update an email list by change one of the properties and calling `save()`.

```
$emailList->name = 'Updated name';
$emailList->save();
```

You can delete an email list by calling `delete()`.

```
$emailList->delete();
```

### Working with subscribers

[](#working-with-subscribers)

To get all subscribers of a list, you can call `subscribers()` on an email list.

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$subscribers = Mailcoach::emailList('')->subscribers();
```

Optionally, you can pass filters to `subscribers()`. Here how to get all subscribers with a Gmail-address.

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$subscribers = Mailcoach::emailList('')
   ->subscribers(['filter[email]=gmail.com']);
```

Alternatively, you can call `subscribers()` on `$mailcoach`

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$subscribers = Mailcoach::subscribers('', $optionalFilters);
```

There's also a convenience method to quickly get a subscriber from a list.

```
// returns instance of Spatie\MailcoachSdk\Resources\Subscriber
// or null if the subscriber does not exist.

$subscriber = $emaillist->subscriber('john@example.com');
```

Alternatively, you can get a subscriber by its UUID:

```
$subscriber = $mailcoach->subscriber('');
```

This how you can create a subscriber:

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$subscriber = Mailcoach::createSubscriber(
    emailListUuid: '',
    attributes: [
        'email' => '',
        'first_name' => 'John',
        'last_name' => 'Doe',
        'tags' => ['Newsletter'],
    ]);
```

You can get properties of a subscriber:

```
$subscriber->firstName;
$subscriber->email;
// ...
```

Take a look at the source code of `Spatie\MailcoachSdk\Resources\Subscriber` to see the list of available properties.

You can update a subscriber by change one of the properties and calling `save()`.

```
$subscriber->firstName = 'Updated name';
$subscriber->save();
```

You can confirm, unsubscribe and delete a subscriber by calling these methods.

```
$subscriber->confirm();
$subscriber->unsubscribe();
$subscriber->delete();
```

### Working with campaigns

[](#working-with-campaigns)

Here's how to get all campaigns.

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$campaigns = Mailcoach::campaigns();
```

You can also get a single campaign();

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$campaign = Mailcoach::campaign('');
```

This is how you can create a campaign:

```
use Spatie\MailcoachSdk\Facades\Mailcoach;

$campaign = Mailcoach::createCampaign([
   'name' => 'My new campaign',
   'subject' => 'Here is some fantastic content for you',
   'email_list_uuid' => '',

   // optionally, you can specify the uuid of a template
   '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',
    ],
]);
```

You can get properties of a campaign:

```
$campaign->name;
$campaign->subject;
// ...
```

Take a look at the source code of `Spatie\MailcoachSdk\Resources\Campaign` to see the list of available properties.

You can update a campaign by change one of the properties and calling `save()`.

```
$campaign->name = 'Campaign';
$campaign->save();
```

A test mail will be sent when calling `sendTest()`:

```
// sending a test to a single person
$campaign->sendTest('john@example.com');

// sending a test to multiple persons
$campaign->sendTest(['john@example.com', 'jane@example.com']);
```

The campaign will be sent to all subscribers of your list, by calling `send()`:

```
$campaign->send();
```

A campaign can be deleted:

```
$campaign->delete();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance89

Actively maintained with recent releases

Popularity48

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~153 days

Recently: every ~222 days

Total

9

Last Release

62d ago

Major Versions

0.0.1 → 1.0.02022-11-08

PHP version history (3 changes)0.0.1PHP ^8.1

1.2.0PHP ^8.2

1.5.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (26 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (20 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (12 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (5 commits)")[![ash-jc-allen](https://avatars.githubusercontent.com/u/39652331?v=4)](https://github.com/ash-jc-allen "ash-jc-allen (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![the-pulli](https://avatars.githubusercontent.com/u/112799107?v=4)](https://github.com/the-pulli "the-pulli (1 commits)")[![janiskelemen](https://avatars.githubusercontent.com/u/20318292?v=4)](https://github.com/janiskelemen "janiskelemen (1 commits)")[![michaelnabil230](https://avatars.githubusercontent.com/u/46572405?v=4)](https://github.com/michaelnabil230 "michaelnabil230 (1 commits)")[![stephenjude](https://avatars.githubusercontent.com/u/31182887?v=4)](https://github.com/stephenjude "stephenjude (1 commits)")[![1stevengrant](https://avatars.githubusercontent.com/u/112473?v=4)](https://github.com/1stevengrant "1stevengrant (1 commits)")

---

Tags

laravelmailmailcoachnewslettersphpspatielaravellaravel-mailcoach-sdk

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spatie-laravel-mailcoach-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-mailcoach-sdk/health.svg)](https://phpackages.com/packages/spatie-laravel-mailcoach-sdk)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[spatie/laravel-notification-log

Log notifications sent by your Laravel app

207902.8k](/packages/spatie-laravel-notification-log)[spatie/laravel-discord-alerts

Send a message to Discord

151408.0k](/packages/spatie-laravel-discord-alerts)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[xammie/mailbook

Laravel Mail Explorer

482458.3k1](/packages/xammie-mailbook)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
