PHPackages                             spatie/mailcoach-sdk-php - 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/mailcoach-sdk-php

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

spatie/mailcoach-sdk-php
========================

An SDK for using the Mailcoach API in PHP

1.9.5(3mo ago)31546.2k—5.6%19[1 PRs](https://github.com/spatie/mailcoach-sdk-php/pulls)7MITPHPPHP ^8.1CI passing

Since Nov 7Pushed 1mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (33)Used By (7)

An SDK for using the Mailcoach API in PHP
=========================================

[](#an-sdk-for-using-the-mailcoach-api-in-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/350802b87f0a9e84a0824af8f510f21ae88f0ab194e9322424efaea20d913e58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6d61696c636f6163682d73646b2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/mailcoach-sdk-php)[![Tests](https://github.com/spatie/mailcoach-sdk-php/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/spatie/mailcoach-sdk-php/actions/workflows/run-tests.yml)[![PHPStan](https://github.com/spatie/mailcoach-sdk-php/actions/workflows/phpstan.yml/badge.svg)](https://github.com/spatie/mailcoach-sdk-php/actions/workflows/phpstan.yml)[![Total Downloads](https://camo.githubusercontent.com/420b6a378f7ed29702219c0969dde0ae82448d40ee64e7778dd1b5887b0e27c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6d61696c636f6163682d73646b2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/mailcoach-sdk-php)

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:

```
$mailcoach = new \Spatie\MailcoachSdk\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/bae660e609574a29e0731b5707c9ec08988ad24fdd65b23a52ea75a3f2a60611/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6d61696c636f6163682d73646b2d7068702e6a70673f743d31)](https://spatie.be/github-ad-click/mailcoach-sdk-php)

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/mailcoach-sdk-php
```

You must also install Guzzle

```
composer require guzzlehttp/guzzle
```

Usage
-----

[](#usage)

To get started, you must first new up an instance of `Spatie\MailcoachSdk\Mailcoach`

```
use Spatie\MailcoachSdk\Mailcoach;

$mailcoach = new Mailcoach('', '')
```

You can find both the API key and the Mailcoach API endpoint in the "API Tokens" screen of the Mailcoach settings.

### 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

```
$subscribers = $mailcoach->subscribers('emailLists();
```

You can get a single email list:

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

This is how you can create an email list:

```
$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.

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

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

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

Alternatively, you can call `subscribers()` on `$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:

```
$subscriber = $mailcoach->createSubscriber('', [
    'email' => 'john@example.com',
]);
```

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, resubscribe, delete a subscriber, and add or remove tags by calling these methods:

```
$subscriber->confirm();
$subscriber->unsubscribe();
$subscriber->resubscribe();
$subscriber->delete();
$subscriber->addTags(['abandoned-cart', 'product-updates']);
$subscriber->removeTags(['abandoned-cart', 'product-updates']);
```

### Working with campaigns

[](#working-with-campaigns)

Here's how to get all campaigns.

```
$campaigns = $mailcoach->campaigns();
```

You can also get a single campaign();

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

This is how you can create a campaign:

```
$campaign = $this->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();
```

### Working with automations

[](#working-with-automations)

If an automation has a webhook trigger configured, you can trigger it by:

```
$mailcoach->triggerAutomation('', [
    '',
    '',
]);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/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

61

—

FairBetter than 99% of packages

Maintenance85

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity66

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 ~40 days

Recently: every ~46 days

Total

30

Last Release

108d ago

Major Versions

0.0.3 → 1.0.02022-11-08

### 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 (94 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (27 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (19 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (19 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (15 commits)")[![wsamoht](https://avatars.githubusercontent.com/u/5725966?v=4)](https://github.com/wsamoht "wsamoht (6 commits)")[![meminuygur](https://avatars.githubusercontent.com/u/21062398?v=4)](https://github.com/meminuygur "meminuygur (3 commits)")[![Marcel-Wil](https://avatars.githubusercontent.com/u/82112342?v=4)](https://github.com/Marcel-Wil "Marcel-Wil (3 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![michaelnabil230](https://avatars.githubusercontent.com/u/46572405?v=4)](https://github.com/michaelnabil230 "michaelnabil230 (1 commits)")[![ImJustToNy](https://avatars.githubusercontent.com/u/5730766?v=4)](https://github.com/ImJustToNy "ImJustToNy (1 commits)")[![pestaa](https://avatars.githubusercontent.com/u/187342?v=4)](https://github.com/pestaa "pestaa (1 commits)")[![philipsorensen](https://avatars.githubusercontent.com/u/5397535?v=4)](https://github.com/philipsorensen "philipsorensen (1 commits)")[![edalzell](https://avatars.githubusercontent.com/u/6069653?v=4)](https://github.com/edalzell "edalzell (1 commits)")[![smknstd](https://avatars.githubusercontent.com/u/2412608?v=4)](https://github.com/smknstd "smknstd (1 commits)")[![tinusg](https://avatars.githubusercontent.com/u/2152919?v=4)](https://github.com/tinusg "tinusg (1 commits)")[![mariomka](https://avatars.githubusercontent.com/u/1822472?v=4)](https://github.com/mariomka "mariomka (1 commits)")[![ash-jc-allen](https://avatars.githubusercontent.com/u/39652331?v=4)](https://github.com/ash-jc-allen "ash-jc-allen (1 commits)")

---

Tags

spatiemailcoach-sdk-php

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.0k2.6M4](/packages/spatie-laravel-failed-job-monitor)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[spatie/laravel-url-signer

Laravel implementation of spatie/signed-url

717784.1k3](/packages/spatie-laravel-url-signer)[spatie/laravel-database-mail-templates

Render Laravel mailables using a template stored in the database.

446762.6k7](/packages/spatie-laravel-database-mail-templates)[spatie/mjml-php

Convert MJML to HTML using PHP

272668.4k10](/packages/spatie-mjml-php)[spatie/laravel-slack-slash-command

Make a Laravel app respond to a slash command from Slack

254601.2k2](/packages/spatie-laravel-slack-slash-command)

PHPackages © 2026

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