PHPackages                             mailersend/mailersend - 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. mailersend/mailersend

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

mailersend/mailersend
=====================

MailerSend PHP SDK

v0.36.0(3mo ago)801.0M—7.5%28[1 issues](https://github.com/mailersend/mailersend-php/issues)[3 PRs](https://github.com/mailersend/mailersend-php/pulls)6MITPHPPHP ^7.4 || ^8.0 &lt;8.6CI passing

Since Aug 12Pushed 1mo ago3 watchersCompare

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

READMEChangelog (10)Dependencies (15)Versions (50)Used By (6)

[![](https://camo.githubusercontent.com/0feba5e88bb82404f190f6c877d7ecaf9c17f0b0ffe4f7fb82928bae60104ed7/68747470733a2f2f7777772e6d61696c657273656e642e636f6d2f696d616765732f6c6f676f2e737667)](https://www.mailersend.com)

MailerSend PHP SDK

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE.md) [![build badge](https://github.com/mailersend/mailersend-php/actions/workflows/php.yml/badge.svg)](https://github.com/mailersend/mailersend-php/actions/workflows/php.yml/badge.svg) [![analysis badge](https://github.com/mailersend/mailersend-php/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/mailersend/mailersend-php/actions/workflows/static-analysis.yml/badge.svg)

Table of Contents
=================

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Email API](#email-api)
        - [Send an email](#send-an-email)
        - [Add CC, BCC recipients](#cc-bcc-recipients)
        - [Send a template-based email](#template)
        - [Personalization](#personalization)
        - [Send an email with attachment](#attachments)
        - [Send a scheduled message](#send-a-scheduled-message)
        - [Send email with precedence bulk header](#precedence-bulk-header)
        - [Send email with custom headers](#custom-headers)
    - [Bulk emails API](#bulk-email-api)
        - [Send bulk email](#send-bulk-email)
        - [Get bulk email status](#get-bulk-email-status)
    - [Inbound routing](#inbound-routing)
        - [Get a list of inbound routes](#get-a-list-of-inbound-routes)
        - [Get a single inbound route](#get-a-single-inbound-route)
        - [Add an inbound route](#add-an-inbound-route)
        - [Update an inbound route](#update-an-inbound-route)
        - [Delete an inbound route](#delete-an-inbound-route)
    - [Activity API](#activity)
        - [Get a list of activities](#get-a-list-of-activities)
        - [Get a single activity](#get-a-single-activity)
    - [Analytics API](#analytics)
        - [Get activity data by date](#get-activity-data-by-date)
        - [Opens by country](#opens-by-country)
        - [Opens by user-agent](#opens-by-user-agent)
        - [Opens by reading environment](#opens-by-reading-environment)
    - [Domains API](#domains)
        - [Get a list of domains](#get-a-list-of-domains)
        - [Get domain](#get-domain)
        - [Add a domain](#add-a-domain)
        - [Delete domain](#delete-domain)
        - [Get a list of recipients per domain](#get-a-list-of-recipients-per-domain)
        - [Update domain settings](#update-domain-settings)
        - [Verify a domain](#verify-a-domain)
        - [Get DNS records](#get-dns-records)
    - [Messages API](#messages)
        - [Get a list of messages](#get-a-list-of-messages)
        - [Get info on a message](#get-info-on-a-message)
    - [Scheduled messages API](#scheduled-messages)
        - [Get a list of scheduled messages](#get-a-list-of-scheduled-messages)
        - [Get a single scheduled message](#get-a-single-scheduled-message)
        - [Delete a scheduled message](#delete-a-scheduled-message)
    - [Tokens API](#tokens)
        - [Get all tokens](#get-all-tokens)
        - [Find a token](#find-a-token)
        - [Create a token](#create-a-token)
        - [Change a token name](#change-a-token-name)
        - [Update token](#update-token)
        - [Delete token](#delete-token)
    - [Recipients API](#recipients)
        - [Get a list of recipients](#get-a-list-of-recipients)
        - [Get single recipient](#get-single-recipient)
        - [Delete recipient](#delete-recipient)
        - [Add recipients to a suppression list](#add-recipients-to-a-suppression-list)
        - [Delete recipients from a suppression list](#delete-recipients-from-a-suppression-list)
        - [Get recipients from a suppression list](#get-recipients-from-a-suppression-list)
    - [Webhooks API](#webhooks)
        - [Get a list of webhooks](#get-a-list-of-webhooks)
        - [Get webhook](#get-webhook)
        - [Create webhook](#create-webhook)
        - [Update webhook](#update-webhook)
        - [Delete webhook](#delete-webhook)
    - [Templates API](#templates)
        - [Get a list of templates](#get-a-list-of-templates)
        - [Get a single template](#get-a-single-template)
        - [Delete a template](#delete-a-template)
    - [Email Verification API](#email-verification)
        - [Get all email verification lists](#get-all-email-verification-lists)
        - [Get an email verification list](#get-an-email-verification-list)
        - [Create an email verification list](#create-an-email%E2%80%93verification-list)
        - [Verify an email list](#verify-an-email-list)
        - [Get email verification list results](#get-email-verification-list-results)
    - [SMS API](#sms-api)
        - [Send an sms](#send-sms)
        - [Personalization](#sms-personalization)
    - [SMS phone number API](#sms-numbers-api)
        - [Get a list of sms phone numbers](#get-a-list-of-sms-numbers)
        - [Get an SMS phone number](#get-sms-number)
        - [Update a single SMS phone number](#update-sms-number)
        - [Delete an SMS phone number](#delete-sms-number)
    - [SMS messages API](#sms-messages-api)
        - [Get a list of SMS messages](#get-a-list-of-sms-messages)
        - [Get an SMS message](#get-sms-message)
    - [SMS Activity API](#sms-activity-api)
        - [Get a list of SMS activities](#get-a-list-of-sms-activities)
    - [SMS Recipients API](#sms-recipients-api)
        - [Get a list of SMS recipients](#get-a-list-of-sms-recipients)
        - [Get an SMS recipient](#get-sms-recipient)
        - [Update a single SMS recipient](#update-sms-recipient)
    - [SMS webhooks API](#sms-webhooks-api)
        - [Get a list of SMS webhooks](#get-a-list-of-sms-webhooks)
        - [Get a single SMS webhook](#get-sms-webhook)
        - [Create an SMS webhook](#create-sms-webhook)
        - [Update a single SMS webhook](#update-sms-webhook)
    - [SMS inbound routing API](#sms-inbounds-api)
        - [Get a list of SMS inbound routes](#get-a-list-of-sms-inbounds)
        - [Get a single SMS inbound route](#get-sms-inbound)
        - [Add an SMS inbound route](#create-sms-inbound)
        - [Update an inbound route](#update-sms-inbound)
        - [Delete an SMS inbound route](#delete-sms-inbound)
    - [Sender Identities](#sender-identity-routing)
        - [Get a list of Sender Identities](#get-a-list-of-sender-identity-routes)
        - [Get a single Sender Identity](#get-a-single-sender-identity-route)
        - [Get a single Sender Identity by email](#get-a-single-sender-identity-by-email-route)
        - [Add a Sender\_Identity](#add-a-sender-identity-route)
        - [Update a Sender Identity](#update-a-sender-identity-route)
        - [Update a Sender Identity by email](#update-a-sender-identity-by-email-route)
        - [Delete a Sender Identity](#delete-a-sender-identity-route)
        - [Delete a Sender Identity by email](#delete-a-sender-identity-by-email-route)
    - [SMTP Users](#smtp-users-routing)
        - [Get a list of SMTP Users](#get-a-list-of-smtp-users)
        - [Get a single SMTP User](#get-a-single-smtp-user)
        - [Add SMTP User](#add-smtp-user)
        - [Update SMTP User](#update-smtp-user)
        - [Delete SMTP User](#delete-smtp-user)
    - [Users](#users-routing)
        - [Get a list of Users](#get-a-list-of-users)
        - [Get a single User](#get-a-single-user)
        - [Add a User](#add-a-user)
        - [Update a User](#update-a-user)
        - [Delete a User](#delete-a-user)
        - [Get a list of Invites](#get-a-list-of-invites)
        - [Get a single Invite](#get-a-single-invite)
        - [Resend an Invite](#resend-an-invite)
        - [Cancel an Invite](#cancel-an-invite)
    - [Other endpoints](#other-endpoints)
        - [Get API quota](#get-api-quota)
- [Debugging validation errors](#debugging-validation-errors)
- [Testing](#testing)
- [Support and Feedback](#support-and-feedback)
- [License](#license)

Installation
============

[](#installation)

Requirements
------------

[](#requirements)

- PHP 7.4
- PSR-7 and PSR-18 based HTTP adapter
- An API Key from [mailersend.com](https://www.mailersend.com)

Setup
-----

[](#setup)

This library, after version v0.22.0 is not compatible with Laravel 8.0 or lower. Please use older versions of SDK, or update your Laravel version.

This library is built atop of [PSR-7](https://www.php-fig.org/psr/psr-7/) and [PSR-18](https://www.php-fig.org/psr/psr-18/). You will need to install some implementations for those interfaces.

```
composer require php-http/guzzle7-adapter nyholm/psr7
```

After that you can install the SDK.

```
composer require mailersend/mailersend
```

Finally, add an environment variable called `MAILERSEND_API_KEY` with the appropriate API key.

Optionally, although not recommended, you can manually add the API key when instantiating the `MailerSend` class, like so:

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'your_api_key']);
```

Usage
=====

[](#usage)

Email
-----

[](#email)

### Send an email

[](#send-an-email)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setHtml('This is the HTML content')
    ->setText('This is the text content')
    ->setReplyTo('reply to')
    ->setReplyToName('reply to name');

$mailersend->email->send($emailParams);
```

HTML content is not required. You still can send an email with Text only.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setText('This is the text content');

$mailersend->email->send($emailParams);
```

### Add CC, BCC recipients

[](#add-cc-bcc-recipients)

Send an email with CC and BCC.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$cc = [
    new Recipient('cc@mail.com', 'CC'),
];

$bcc = [
    new Recipient('bcc@mail.com', 'BCC'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setCc($cc)
    ->setBcc($bcc)
    ->setSubject('Subject')
    ->setHtml('This is the HTML content')
    ->setText('This is the text content');

$mailersend->email->send($emailParams);
```

### Send a template-based email

[](#send-a-template-based-email)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$tags = ['tag'];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setTemplateId('ss243wdasd')
    ->setTags($tags);

$mailersend->email->send($emailParams);
```

### Advanced personalization

[](#advanced-personalization)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Personalization;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$personalization = [
    new Personalization('your@client.com', [
        'var' => 'variable',
        'number' => 123,
        'object' => [
            'key' => 'object-value'
        ],
        'objectCollection' => [
            [
                'name' => 'John'
            ],
            [
                'name' => 'Patrick'
            ]
        ],
    ])
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject {$var}')
    ->setHtml('This is the html version with a {$var}.')
    ->setText('This is the text versions with a {$var}.')
    ->setPersonalization($personalization);

$mailersend->email->send($emailParams);
```

### Send email with attachment

[](#send-email-with-attachment)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Attachment;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$attachments = [
    new Attachment(file_get_contents('attachment.jpg'), 'attachment.jpg')
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setHtml('This is the html version.')
    ->setText('This is the text version.')
    ->setAttachments($attachments);

$mailersend->email->send($emailParams);
```

### Send a scheduled message

[](#send-a-scheduled-message)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setHtml('This is the html version.')
    ->setText('This is the text version.')
    ->setSendAt(1665626400);
    ->setPrecedenceBulkHeader(true);

$mailersend->email->send($emailParams);
```

### Send email with precedence bulk header

[](#send-email-with-precedence-bulk-header)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setHtml('This is the html version.')
    ->setText('This is the text version.')
    ->setPrecedenceBulkHeader(true);

$mailersend->email->send($emailParams);
```

### Send an email with tracking

[](#send-an-email-with-tracking)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setHtml('This is the HTML content')
    ->setText('This is the text content')
    ->setTrackClicks(true)
    ->setTrackOpens(true)
    ->setTrackContent(true);

$mailersend->email->send($emailParams);
```

### Send an email with custom headers

[](#send-an-email-with-custom-headers)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
use MailerSend\Helpers\Builder\Header;

$mailersend = new MailerSend(['api_key' => 'key']);

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$headers = [
    new Header('Custom-Header-1', 'Value 1')
    new Header('Custom-Header-2', 'Value 2')
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject')
    ->setHtml('This is the HTML content')
    ->setText('This is the text content')
    ->setHeaders($headers);

$mailersend->email->send($emailParams);
```

Bulk email API
--------------

[](#bulk-email-api)

### Send bulk email

[](#send-bulk-email)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;

$mailersend = new MailerSend();

$bulkEmailParams = [];

$bulkEmailParams[] = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients([
        new Recipient('recipient1@client.com', 'Your Client'),
    ])
    ->setSubject('Subject')
    ->setHtml('This is the HTML content')
    ->setText('This is the text content');

$bulkEmailParams[] = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients([
        new Recipient('recipient2@client.com', 'Your Client'),
    ])
    ->setSubject('Subject')
    ->setHtml('This is the HTML content')
    ->setText('This is the text content');

$mailersend->bulkEmail->send($bulkEmailParams);
```

### Get bulk email status

[](#get-bulk-email-status)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->bulkEmail->getStatus('bulk_email_id');
```

Inbound routing
---------------

[](#inbound-routing)

### Get a list of inbound routes

[](#get-a-list-of-inbound-routes)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->inbound->getAll($domainId = 'domainId', $page = 1, $limit = 10);
```

### Get a single inbound route

[](#get-a-single-inbound-route)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->inbound->find('inboundId');
```

### Add an inbound route

[](#add-an-inbound-route)

Example using only classes:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Inbound;
use \MailerSend\Helpers\Builder\CatchFilter;
use \MailerSend\Helpers\Builder\MatchFilter;
use \MailerSend\Helpers\Builder\Forward;
use \MailerSend\Helpers\Builder\Filter;
use \MailerSend\Common\Constants;

$mailersend = new MailerSend();

$mailersend->inbound->create(
    (new Inbound('domainId', 'name', true))
        ->setInboundDomain('inboundDomain')
        ->setCatchFilter(
            (new CatchFilter(Constants::TYPE_CATCH_RECIPIENT)
                ->addFilter(new Filter(Constants::COMPARER_EQUAL, 'test@mailersend.com'))))
        ->setMatchFilter(
            (new MatchFilter(Constants::TYPE_MATCH_SENDER))
                ->addFilter(new Filter(Constants::COMPARER_EQUAL, 'sender@mailersend.com', 'sender')))
        ->addForward(new Forward(Constants::TYPE_WEBHOOK, 'value'))
        ->setInboundPriority(50)
);
```

Example using both classes and arrays:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Inbound;
use \MailerSend\Helpers\Builder\CatchFilter;
use \MailerSend\Helpers\Builder\MatchFilter;
use \MailerSend\Helpers\Builder\Forward;
use \MailerSend\Common\Constants;

$mailersend = new MailerSend();

$mailersend->inbound->create(
    (new Inbound('domainId', 'name', true))
        ->setInboundDomain('inboundDomain')
        ->setCatchFilter(
            (new CatchFilter(Constants::TYPE_CATCH_RECIPIENT))
                ->setFilters([
                    [
                        'comparer' => Constants::COMPARER_EQUAL,
                        'value' => 'test@mailersend.com',
                    ]
                ])
        )
        ->setMatchFilter(
            (new MatchFilter(Constants::TYPE_MATCH_SENDER))
                ->setFilters([
                    [
                        'comparer' => Constants::COMPARER_EQUAL,
                        'value' => 'sender@mailersend.com',
                        'key' => 'sender',
                    ]
                ])
        )
        ->addForward(new Forward(Constants::TYPE_WEBHOOK, 'value'))
        ->setInboundPriority(50)
);
```

Example using only arrays:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Inbound;
use \MailerSend\Helpers\Builder\CatchFilter;
use \MailerSend\Helpers\Builder\MatchFilter;
use \MailerSend\Helpers\Builder\Forward;
use \MailerSend\Common\Constants;

$mailersend = new MailerSend();

$mailersend->inbound->create(
    (new Inbound('domainId', 'name', true))
        ->setInboundDomain('inboundDomain')
        ->setCatchFilter([
            'type' => Constants::TYPE_CATCH_RECIPIENT,
            'filters' => [
                [
                    'comparer' => Constants::COMPARER_EQUAL,
                    'value' => 'test@mailersend.com',
                ],
            ],
        ])
        ->setMatchFilter([
            'type' => Constants::TYPE_MATCH_SENDER,
            'filters' => [
                [
                    'comparer' => Constants::COMPARER_EQUAL,
                    'value' => 'sender@mailersend.com',
                    'key' => 'sender',
                ],
            ],
        ])
        ->setForwards([
            [
                'type' => Constants::TYPE_WEBHOOK,
                'value' => 'value',
            ]
        ])
        ->setInboundPriority(50)
);
```

### Update an inbound route

[](#update-an-inbound-route)

The examples on building the `Inbound` object portrayed in the 'Add an inbound route' also apply in here.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Inbound;
use \MailerSend\Helpers\Builder\CatchFilter;
use \MailerSend\Helpers\Builder\MatchFilter;
use \MailerSend\Helpers\Builder\Forward;
use \MailerSend\Common\Constants;

$mailersend = new MailerSend();

$mailersend->inbound->update(
    'inboundId',
    (new Inbound('domainId', 'name', true))
        ->setInboundDomain('inboundDomain')
        ->setCatchFilter(
            (new CatchFilter(Constants::TYPE_CATCH_ALL))
        )
        ->setMatchFilter(new MatchFilter(Constants::TYPE_MATCH_ALL))
        ->addForward(new Forward(Constants::TYPE_WEBHOOK, 'value'))
);
```

### Delete an inbound route

[](#delete-an-inbound-route)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->inbound->delete('inboundId');
```

Activity
--------

[](#activity)

### Get a list of activities

[](#get-a-list-of-activities)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\ActivityParams;

$mailersend = new MailerSend();

$activityParams = (new ActivityParams())
                    ->setPage(3)
                    ->setLimit(15)
                    ->setDateFrom(1623073576)
                    ->setDateTo(1623074976)
                    ->setEvent(['queued', 'sent']);

$mailersend->activity->getAll('domainId', $activityParams);
```

### Get a single activity

[](#get-a-single-activity)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\ActivityParams;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->activity->find('activity_id');
```

Analytics
---------

[](#analytics)

### Get activity data by date

[](#get-activity-data-by-date)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\ActivityAnalyticsParams;
use MailerSend\Common\Constants;

$mailersend = new MailerSend();

$activityAnalyticsParams = (new ActivityAnalyticsParams(100, 101))
                    ->setDomainId('domain_id')
                    ->setGroupBy(Constants::GROUP_BY_DAYS)
                    ->setTags(['tag'])
                    ->setEvent(['queued', 'sent']);

$mailersend->analytics->activityDataByDate($activityAnalyticsParams);
```

### Opens by country

[](#opens-by-country)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\OpensAnalyticsParams;

$mailersend = new MailerSend();

$opensAnalyticsParams = (new OpensAnalyticsParams(100, 101))
                    ->setDomainId('domain_id')
                    ->setTags(['tag']);

$mailersend->analytics->opensByCountry($opensAnalyticsParams);
```

### Opens by user-agent

[](#opens-by-user-agent)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\OpensAnalyticsParams;

$mailersend = new MailerSend();

$opensAnalyticsParams = (new OpensAnalyticsParams(100, 101))
                    ->setDomainId('domain_id')
                    ->setTags(['tag']);

$mailersend->analytics->opensByUserAgentName($opensAnalyticsParams);
```

### Opens by reading environment

[](#opens-by-reading-environment)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\OpensAnalyticsParams;

$mailersend = new MailerSend();

$opensAnalyticsParams = (new OpensAnalyticsParams(100, 101))
                    ->setDomainId('domain_id')
                    ->setTags(['tag']);

$mailersend->analytics->opensByReadingEnvironment($opensAnalyticsParams);
```

Domains
-------

[](#domains)

### Get a list of domains

[](#get-a-list-of-domains)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->domain->getAll($page = 1, $limit = 10, $verified = true);
```

### Get domain

[](#get-domain)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->domain->find('domain_id');
```

### Add a domain

[](#add-a-domain)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\DomainParams;

$mailersend = new MailerSend();

$domainParams = (new DomainParams('domainName'))
                    ->setReturnPathSubdomain('returnPath')
                    ->setCustomTrackingSubdomain('customTracking')
                    ->getInboundRoutingSubdomain('inboundRouting');

$mailersend->domain->create($domainParams);
```

### Delete domain

[](#delete-domain)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->domain->delete('domain_id');
```

### Get a list of recipients per domain

[](#get-a-list-of-recipients-per-domain)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->domain->recipients($domainId = 'domain_id', $page = 1, $limit = 10);
```

### Update domain settings

[](#update-domain-settings)

Here you can set as many properties as you need, one or multiple.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\DomainSettingsParams;

$mailersend = new MailerSend();

$domainSettingsParam = (new DomainSettingsParams())
                            ->setSendPaused(true)
                            ->setTrackClicks(true)
                            ->setTrackOpens(false)
                            ->setTrackUnsubscribe(false)
                            ->setTrackContent(true)
                            ->setTrackUnsubscribeHtml('html')
                            ->setTrackUnsubscribePlain('plain')
                            ->setCustomTrackingEnabled(true)
                            ->setCustomTrackingSubdomain(false);

$mailersend->domain->domainSettings($domainId = 'domain_id', $domainSettingsParam);
```

### Verify a domain

[](#verify-a-domain)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->domain->verify('domain_id');
```

### Get DNS records

[](#get-dns-records)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->domain->getDnsRecords('domain_id');
```

Messages
--------

[](#messages)

### Get a list of messages

[](#get-a-list-of-messages)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->messages->get($limit = 100, $page = 3);
```

### Get info on a message

[](#get-info-on-a-message)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->messages->find('message_id');
```

Scheduled Messages
------------------

[](#scheduled-messages)

### Get a list of scheduled messages

[](#get-a-list-of-scheduled-messages)

```
use MailerSend\MailerSend;
use \MailerSend\Common\Constants;

$mailersend = new MailerSend();

$mailersend->scheduleMessages->getAll(
    'domain_id',
    Constants::STATUS_SCHEDULED,
    $limit = 100,
    $page = 3
)
```

### Get a single scheduled message

[](#get-a-single-scheduled-message)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->scheduleMessages->find('message_id');
```

### Delete a scheduled message

[](#delete-a-scheduled-message)

```
use MailerSend\MailerSend;
use \MailerSend\Common\Constants;

$mailersend = new MailerSend();

$mailersend->scheduleMessages->delete('message_id');
```

Tokens
------

[](#tokens)

### Get all tokens

[](#get-all-tokens)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->token->getAll($page = 1, $limit = 10);
```

### Find a token

[](#find-a-token)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->token->find('token_id');
```

### Create a token

[](#create-a-token)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;

$mailersend = new MailerSend();

$mailersend->token->create(
    new TokenParams('token name', 'domainId', TokenParams::ALL_SCOPES)
);
```

Because of security reasons, we only allow access token appearance once during creation. In order to see the access token created you can do:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;

$mailersend = new MailerSend();

$response = $mailersend->token->create(
    new TokenParams('token name', 'domainId', TokenParams::ALL_SCOPES)
);

echo $response['body']['data']['accessToken'];
```

### Change a token name

[](#change-a-token-name)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;

$mailersend = new MailerSend();

$mailersend->token->changeName('token_id', 'new name');
```

### Update token

[](#update-token)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;

$mailersend = new MailerSend();

$mailersend->token->update('token_id', TokenParams::STATUS_PAUSE); // PAUSE
$mailersend->token->update('token_id', TokenParams::STATUS_UNPAUSE); // UNPAUSE
```

### Delete Token

[](#delete-token)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;

$mailersend = new MailerSend();

$mailersend->token->delete('token_id');
```

Recipients
----------

[](#recipients)

### Get a list of recipients

[](#get-a-list-of-recipients)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->recipients->get(null, $limit = 100, $page = 3);
// Or for a specific domain
$mailersend->recipients->get('domain_id', $limit = 100, $page = 3);
```

### Get single recipient

[](#get-single-recipient)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->recipients->find('recipient_id');
```

### Delete recipient

[](#delete-recipient)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->recipients->delete('recipient_id');
```

### Add recipients to a suppression list

[](#add-recipients-to-a-suppression-list)

**Blocklist**

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\BlocklistParams;

$mailersend = new MailerSend();

$params = (new BlocklistParams())
    ->setDomainId('domain_id')
    ->setRecipients(['recipient_one', 'recipient_two'])
    ->setPatterns(['pattern_one', 'pattern_two']);

$mailersend->blocklist->create($params);
```

**Hard Bounces**

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SuppressionParams;

$mailersend = new MailerSend();

$params = (new SuppressionParams())
    ->setDomainId('domain_id')
    ->setRecipients(['recipient_one', 'recipient_two']);

$mailersend->hardBounce->create($params);
```

**Spam Complaints**

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SuppressionParams;

$mailersend = new MailerSend();

$params = (new SuppressionParams())
    ->setDomainId('domain_id')
    ->setRecipients(['recipient_one', 'recipient_two']);

$mailersend->spamComplaint->create($params);
```

**Unsubscribes**

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SuppressionParams;

$mailersend = new MailerSend();

$params = (new SuppressionParams())
    ->setDomainId('domain_id')
    ->setRecipients(['recipient_one', 'recipient_two']);

$mailersend->unsubscribe->create($params);
```

### Delete recipients from a suppression list

[](#delete-recipients-from-a-suppression-list)

**Blocklist**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

// Delete specific instances
$mailersend->blocklist->delete(['id_one', 'id_two']);

// or delete all
$mailersend->blocklist->delete(null, true);

// You can also specify the domain
$mailersend->blocklist->delete(['id'], false, 'domain_id');
```

**Hard Bounces**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

// Delete specific instances
$mailersend->hardBounce->delete(['id_one', 'id_two']);

// or delete all
$mailersend->hardBounce->delete(null, true);

// You can also specify the domain
$mailersend->hardBounce->delete(['id'], false, 'domain_id');
```

**Spam Complaints**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

// Delete specific instances
$mailersend->spamComplaint->delete(['id_one', 'id_two']);

// or delete all
$mailersend->spamComplaint->delete(null, true);

// You can also specify the domain
$mailersend->spamComplaint->delete(['id'], false, 'domain_id');
```

**Unsubscribes**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

// Delete specific instances
$mailersend->unsubscribe->delete(['id_one', 'id_two']);

// or delete all
$mailersend->unsubscribe->delete(null, true);

// You can also specify the domain
$mailersend->unsubscribe->delete(['id'], false, 'domain_id');
```

**On Hold List**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

// Delete specific instances
$mailersend->onHoldList->delete(['id_one', 'id_two']);

// or delete all
$mailersend->onHoldList->delete(null, true);
```

### Get recipients from a suppression list

[](#get-recipients-from-a-suppression-list)

**Blocklist**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->blocklist->getAll('domain_id', 15);
```

**Hard Bounces**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->hardBounce->getAll('domain_id', 15);
```

**Spam Complaints**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->spamComplaint->getAll('domain_id', 15);
```

**Unsubscribes**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->unsubscribe->getAll('domain_id', 15);
```

**On Hold List**

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->onHoldList->getAll('domain_id', 15);
```

Webhooks
--------

[](#webhooks)

### Get a list of webhooks

[](#get-a-list-of-webhooks)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->webhooks->get('domain_id');
```

### Get webhook

[](#get-webhook)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->webhooks->find('webhook_id');
```

### Create webhook

[](#create-webhook)

```
use MailerSend\Helpers\Builder\WebhookParams;
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->webhooks->create(
    new WebhookParams('https://webhook_url', 'Webhook name', WebhookParams::ALL_ACTIVITIES, 'domain_id')
);

// Or a disabled webhook

$mailersend->webhooks->create(
    new WebhookParams('https://webhook_url', 'Webhook name', WebhookParams::ALL_ACTIVITIES, 'domain_id', false)
);
```

### Update webhook

[](#update-webhook)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\WebhookParams;

$mailersend = new MailerSend();

$mailersend->webhooks->update('webhook_id', 'https://webhook_url', 'Webhook name', WebhookParams::ALL_ACTIVITIES);

// Enable webhook
$mailersend->webhooks->update('webhook_id', 'https://webhook_url', 'Webhook name', WebhookParams::ALL_ACTIVITIES, true);

// Disable webhook
$mailersend->webhooks->update('webhook_id', 'https://webhook_url', 'Webhook name', WebhookParams::ALL_ACTIVITIES, false);
```

### Delete webhook

[](#delete-webhook)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->webhooks->delete('webhook_id');
```

*If, at the moment, some endpoint is not available, please use `cURL` and other available tools to access it. [Refer to official API docs for more info](https://developers.mailersend.com/).*

Templates
---------

[](#templates)

### Get a list of templates

[](#get-a-list-of-templates)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

// Get all templates of an account
$mailersend->template->getAll();

// Get all templates of a domain
$mailersend->template->getAll('domain_id');

// Get page 2 of templates with 20 records per page
$mailersend->template->getAll('domain_id', 2, 20);
```

### Get a single template

[](#get-a-single-template)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->template->find('template_id');
```

### Delete a template

[](#delete-a-template)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->template->delete('template_id');
```

Email Verification
------------------

[](#email-verification)

### Get all email verification lists

[](#get-all-email-verification-lists)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->emailVerification->getAll($page = 1, $limit = 10);
```

### Get an email verification list

[](#get-an-email-verification-list)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->emailVerification->find('email_verification_id');
```

### Create an email verification list

[](#create-an-email-verification-list)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\EmailVerificationParams;

$mailersend = new MailerSend();

$emailVerificationParams = (new EmailVerificationParams('file.csv'))
    ->setEmailAddresses(['test@mail.com']);

$mailersend->emailVerification->create($emailVerificationParams);
```

### Verify an email list

[](#verify-an-email-list)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->emailVerification->verify('email_verification_id');
```

### Get email verification list results

[](#get-email-verification-list-results)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\EmailVerificationParams;

$mailersend = new MailerSend();

$mailersend->emailVerification->getResults(
        $emailVerificationId = 'email_verification_id',
        $page = 1,
        $limit = 10,
        $results = [
            EmailVerificationParams::TYPO,
            EmailVerificationParams::CATCH_ALL,
        ],
    );
```

SMS
---

[](#sms)

### Send SMS

[](#send-sms)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsParams;

$mailersend = new MailerSend();

$smsParams = (new SmsParams())
    ->setFrom('+12065550101')
    ->setTo(['+12065550102'])
    ->addRecipient('+12065550103')
    ->setText('Text');

$sms = $mailersend->sms->send($smsParams);
```

### Personalization

[](#personalization)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsParams;

$mailersend = new MailerSend();

$smsParams = (new SmsParams())
    ->setFrom('+12065550101')
    ->setTo(['+12065550102'])
    ->setText('Text {{ var }}')
    ->setPersonalization([
        new SmsPersonalization('+12065550102', [
            'var' => 'variable',
            'number' => 123,
            'object' => [
                'key' => 'object-value'
            ],
            'objectCollection' => [
                [
                    'name' => 'John'
                ],
                [
                    'name' => 'Patrick'
                ]
            ],
        ])
    ]);

$sms = $mailersend->sms->send($smsParams);
```

SMS phone numbers
-----------------

[](#sms-phone-numbers)

### Get a list of SMS phone numbers

[](#get-a-list-of-sms-phone-numbers)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$sms = $mailersend->smsNumber->getAll($page = 1, $limit = 10, $paused = true);
```

### Get an SMS phone number

[](#get-an-sms-phone-number)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$sms = $mailersend->smsNumber->find('sms_number_id');
```

### Update a single SMS phone number

[](#update-a-single-sms-phone-number)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$sms = $mailersend->smsNumber->update('sms_number_id', $paused = true);
```

### Delete an SMS phone number

[](#delete-an-sms-phone-number)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$sms = $mailersend->smsNumber->delete('sms_number_id');
```

SMS messages API
----------------

[](#sms-messages-api)

### Get a list of SMS messages

[](#get-a-list-of-sms-messages)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsMessages = $mailersend->smsMessage->getAll($page = 1, $limit = 10);
```

### Get an SMS message

[](#get-an-sms-message)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsMessage = $mailersend->smsMessage->find('sms_message_id');
```

SMS activity API
----------------

[](#sms-activity-api)

### Get a list of SMS activities

[](#get-a-list-of-sms-activities)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsActivityParams;

$mailersend = new MailerSend();

$smsActivityParams = (new SmsActivityParams())
    ->setSmsNumberId('sms_number_id')
    ->setDateFrom(1623073576)
    ->setDateTo(1623074976)
    ->setStatus(['queued'])
    ->setPage(3)
    ->setLimit(15);

$smsActivity = $mailersend->smsActivity->getAll($smsActivityParams);
```

SMS recipients API
------------------

[](#sms-recipients-api)

### Get a list of SMS recipients

[](#get-a-list-of-sms-recipients)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsRecipientParams;

$mailersend = new MailerSend();

$smsRecipientParams = (new SmsRecipientParams())
    ->setSmsNumberId('sms_number_id')
    ->setStatus('opt_out')
    ->setPage(3)
    ->setLimit(15);

$smsRecipients = $mailersend->smsRecipient->getAll($smsRecipientParams);
```

### Get an SMS recipient

[](#get-an-sms-recipient)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsRecipient->find('sms_recipient_id');
```

### Update a single SMS recipient

[](#update-a-single-sms-recipient)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsRecipient->update('sms_recipient_id', $status = 'opt_out');
```

SMS webhooks API
----------------

[](#sms-webhooks-api)

### Get a list of SMS webhooks

[](#get-a-list-of-sms-webhooks)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsWebhook->get('sms_number_id');
```

### Get a single SMS webhook

[](#get-a-single-sms-webhook)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsWebhook->find('sms_webhook_id');
```

### Create a single SMS webhook

[](#create-a-single-sms-webhook)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsWebhookParams;

$mailersend = new MailerSend();

$smsWebhookParams = (new SmsWebhookParams())
    ->setSmsNumberId('sms_number_id')
    ->setName('Name')
    ->setUrl('https://mailersend.com/sms_webhook')
    ->setEvents(['sms.sent', 'sms.delivered', 'sms.failed'])
    ->setEnabled(false);

$smsRecipients = $mailersend->smsWebhook->create($smsWebhookParams);
```

### Update a single SMS webhook

[](#update-a-single-sms-webhook)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsWebhookParams;

$mailersend = new MailerSend();

$smsWebhookParams = (new SmsWebhookParams())
    ->setSmsNumberId('sms_number_id')
    ->setName('Name')
    ->setUrl('https://mailersend.com/sms_webhook')
    ->setEvents(['sms.sent', 'sms.delivered', 'sms.failed'])
    ->setEnabled(false);

$smsRecipients = $mailersend->smsWebhook->update($smsWebhookParams);
```

SMS inbound routing API
-----------------------

[](#sms-inbound-routing-api)

### Get a list of SMS inbound routes

[](#get-a-list-of-sms-inbound-routes)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsInbound->getAll($smsNumberId = 'sms_number_id', $enabled = true, $page = 3, $limit = 15);
```

### Get a single SMS inbound route

[](#get-a-single-sms-inbound-route)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsInbound->find('sms_inbound_id');
```

### Add an SMS inbound route

[](#add-an-sms-inbound-route)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsInbound;
use MailerSend\Helpers\Builder\SmsInboundFilter;

$mailersend = new MailerSend();

$smsInboundParams = (new SmsInbound())
    ->setSmsNumberId('sms_number_id')
    ->setName('Name')
    ->setForwardUrl('https://mailersend.com/inbound_webhook')
    ->setFilter(new SmsInboundFilter($comparer = 'starts-with', $value = 'Stop'))
    ->setEnabled(true);

$smsRecipients = $mailersend->smsInbound->create($smsInboundParams);
```

### Update an inbound route

[](#update-an-inbound-route-1)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsInbound;
use MailerSend\Helpers\Builder\SmsInboundFilter;

$mailersend = new MailerSend();

$smsInboundParams = (new SmsInbound())
    ->setSmsNumberId('sms_number_id')
    ->setName('Name')
    ->setForwardUrl('https://mailersend.com/inbound_webhook')
    ->setFilter(new SmsInboundFilter($comparer = 'starts-with', $value = 'Stop'))
    ->setEnabled(true);

$smsRecipients = $mailersend->smsInbound->update('sms_inbound_id', $smsInboundParams);
```

### Delete an inbound route

[](#delete-an-inbound-route-1)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$smsRecipients = $mailersend->smsInbound->delete('sms_inbound_id');
```

Sender identities
-----------------

[](#sender-identities)

### Get a list of Sender Identities

[](#get-a-list-of-sender-identities)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->senderIdentity->getAll($domainId = 'domainId', $page = 1, $limit = 10);
```

### Get a single Sender Identity

[](#get-a-single-sender-identity)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->senderIdentity->find('identityId');
```

### Get a single Sender Identity by email

[](#get-a-single-sender-identity-by-email)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->senderIdentity->findByEmail('email');
```

### Add a Sender Identity

[](#add-a-sender-identity)

Example using only classes:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SenderIdentity;

$mailersend = new MailerSend();

$mailersend->senderIdentity->create(
    (new SenderIdentity('domainId', 'name', 'email'))
);
```

Example using all options:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SenderIdentity;

$mailersend = new MailerSend();

$mailersend->senderIdentity->create(
    (new SenderIdentity('domainId', 'name', 'email'))
        ->setReplyToName("John Doe")
        ->setReplyToEmail("john@test.com"))
        ->setAddNote(true)
        ->setPersonalNote("Hi John, please use this token")
);
```

### Update a Sender Identity

[](#update-a-sender-identity)

The examples on building the `Sender Identity` object portrayed in the 'Add a Sender Identity' also apply in here.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SenderIdentity;

$mailersend = new MailerSend();

$mailersend->senderIdentity->update(
    'identityId',
    (new SenderIdentity('domainId', 'name', 'email'))
        ->setReplyToName("John Doe")
        ->setReplyToEmail("john@test.com"))
        ->setAddNote(true)
        ->setPersonalNote("Hi John, please use this token")
);
```

### Update a Sender Identity by email

[](#update-a-sender-identity-by-email)

The examples on building the `Sender Identity` object portrayed in the 'Add a Sender Identity' also apply in here.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SenderIdentity;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->senderIdentity->updateByEmail(
    'identityId',
    (new SenderIdentity('domainId', 'name', 'email'))
        ->setReplyToName("John Doe")
        ->setReplyToEmail("john@test.com"))
        ->setAddNote(true)
        ->setPersonalNote("Hi John, please use this token")
);
```

### Delete a Sender Identity

[](#delete-a-sender-identity)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->senderIdentity->delete('identityId');
```

### Delete a Sender Identity by email

[](#delete-a-sender-identity-by-email)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->senderIdentity->deleteByEmail('email');
```

SMTP Users
----------

[](#smtp-users)

### Get a list of SMTP Users

[](#get-a-list-of-smtp-users)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->getAll('domainId', 25);
```

### Get a single SMTP User

[](#get-a-single-smtp-user)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->find('domainId', 'smtpUserId');
```

### Add SMTP User

[](#add-smtp-user)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\UserParams;
use MailerSend\Helpers\Builder\SmtpUserParams;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->create(
    'domainId',
    (new SmtpUserParams('name'))
        ->setEnabled(false)
);
```

### Update SMTP User

[](#update-smtp-user)

The examples on building the `SMTP User` object portrayed in the 'Add SMTP User' also apply in here.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\UserParams;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->update(
    'domainId',
    'smtpUserId',
    (new SmtpUserParams('New name'))
        ->setEnabled(false)
);
```

### Delete SMTP User

[](#delete-smtp-user)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->smtpUser->delete('domainId', 'smtpUserId');
```

Users
-----

[](#users)

### Get a list of Users

[](#get-a-list-of-users)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->user->getAll();
```

### Get a single User

[](#get-a-single-user)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->user->find('userId');
```

### Add a User

[](#add-a-user)

Example using only classes:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\UserParams;
use MailerSend\Common\Roles;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->user->create(
    (new UserParams('email', Roles::ADMIN))
);
```

Example using all options:

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\UserParams;
use MailerSend\Common\Roles;
use MailerSend\Common\Permissions;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->user->create(
    (new UserParams('email', Roles::CUSTOM_USER))
        ->setDomains(['domainId', 'anotherDomainId'])
        ->setTemplates(['templateId', 'anotherTemplateId'])
        ->setPermissions([Permissions::READ_OWN_TEMPLATES])
        ->setRequiresPeriodicPasswordChange(true)
);
```

### Update a User

[](#update-a-user)

The examples on building the `User` object portrayed in the 'Add a User' also apply in here.

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\UserParams;
use MailerSend\Common\Roles;
use MailerSend\Common\Permissions;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->user->update(
    'userId',
    (new UserParams())
        ->setRole(Roles::CUSTOM_USER)
        ->setDomains(['domainId', 'anotherDomainId'])
        ->setTemplates(['templateId', 'anotherTemplateId'])
        ->setPermissions([Permissions::READ_OWN_TEMPLATES])
        ->setRequiresPeriodicPasswordChange(true)
);
```

### Delete a User

[](#delete-a-user)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->user->delete('userId');
```

&lt;a name="get-a-list-of-invites&gt;

### Get a list of Invites

[](#get-a-list-of-invites)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->invite->getAll();
```

### Get a single Invite

[](#get-a-single-invite)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->invite->find('inviteId');
```

### Resend an Invite

[](#resend-an-invite)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->invite->resend('inviteId');
```

&lt;a name="cancel-an-invite&gt;

### Cancel an Invite

[](#cancel-an-invite)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$mailersend->invite->cancel('inviteId');
```

Other endpoints
---------------

[](#other-endpoints)

### Get API quota

[](#get-api-quota)

```
use MailerSend\MailerSend;

$mailersend = new MailerSend();

$mailersend->apiQuota->get();
```

Debugging validation errors
===========================

[](#debugging-validation-errors)

```
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
use MailerSend\Exceptions\MailerSendValidationException;
use MailerSend\Exceptions\MailerSendRateLimitException;

$mailersend = new MailerSend();

$recipients = [
    new Recipient('your@client.com', 'Your Client'),
];

$emailParams = (new EmailParams())
    ->setFrom('your@domain.com')
    ->setFromName('Your Name')
    ->setRecipients($recipients)
    ->setSubject('Subject {$var}')
    ->setHtml('This is the html version with a {$var}.')
    ->setText('This is the text versions with a {$var}.');

try{
    $mailersend->email->send($emailParams);
} catch(MailerSendValidationException $e){
    // See src/Exceptions/MailerSendValidationException.php for more more info
    print_r($e->getResponse()->getBody()->getContents());
    print_r($e->getBody());
    print_r($e->getHeaders());
    print_r($e->getErrors());
    print_r($e->getStatusCode());
} catch (MailerSendRateLimitException $e) {
    print_r($e->getHeaders());
    print_r($e->getResponse()->getBody()->getContents());
}
```

Testing
=======

[](#testing)

```
composer test
```

Support and Feedback
====================

[](#support-and-feedback)

In case you find any bugs, submit an issue directly here in GitHub.

You are welcome to create SDK for any other programming language.

If you have any troubles using our API or SDK free to contact our support by email

The official documentation is at

License
=======

[](#license)

[The MIT License (MIT)](LICENSE.md)

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity55

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity75

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

Recently: every ~76 days

Total

44

Last Release

106d ago

PHP version history (5 changes)v0.1.0PHP ^7.4

v0.2PHP ^7.4|^8.0

v0.32.0PHP ^7.4 || ^8.0 &lt;8.4

v0.34.0PHP ^7.4 || ^8.0 &lt;8.5

v0.36.0PHP ^7.4 || ^8.0 &lt;8.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/b2cbfafd3d2cbdcf20ea2171ee4a0e9cd021f928afbc44891c8a58fb84168a55?d=identicon)[mailersend](/maintainers/mailersend)

---

Top Contributors

[![JoaoFSCruz](https://avatars.githubusercontent.com/u/26048679?v=4)](https://github.com/JoaoFSCruz "JoaoFSCruz (51 commits)")[![PeterOcansey](https://avatars.githubusercontent.com/u/52463144?v=4)](https://github.com/PeterOcansey "PeterOcansey (33 commits)")[![doobas](https://avatars.githubusercontent.com/u/14978210?v=4)](https://github.com/doobas "doobas (32 commits)")[![fosron](https://avatars.githubusercontent.com/u/3708631?v=4)](https://github.com/fosron "fosron (20 commits)")[![mailersend-renovate[bot]](https://avatars.githubusercontent.com/u/65919112?v=4)](https://github.com/mailersend-renovate[bot] "mailersend-renovate[bot] (8 commits)")[![heybardi](https://avatars.githubusercontent.com/u/24764312?v=4)](https://github.com/heybardi "heybardi (5 commits)")[![dinomh](https://avatars.githubusercontent.com/u/25065792?v=4)](https://github.com/dinomh "dinomh (3 commits)")[![osvaldoM](https://avatars.githubusercontent.com/u/11247633?v=4)](https://github.com/osvaldoM "osvaldoM (3 commits)")[![Nyanko-sensei](https://avatars.githubusercontent.com/u/6950776?v=4)](https://github.com/Nyanko-sensei "Nyanko-sensei (2 commits)")[![opheus2](https://avatars.githubusercontent.com/u/31169044?v=4)](https://github.com/opheus2 "opheus2 (1 commits)")[![ziltoidbot](https://avatars.githubusercontent.com/u/10959403?v=4)](https://github.com/ziltoidbot "ziltoidbot (1 commits)")[![KarolisNordstreet](https://avatars.githubusercontent.com/u/121024814?v=4)](https://github.com/KarolisNordstreet "KarolisNordstreet (1 commits)")[![Stasky745](https://avatars.githubusercontent.com/u/72012651?v=4)](https://github.com/Stasky745 "Stasky745 (1 commits)")

---

Tags

emailhacktoberfestmailersendphptransactional-emailsemailtransactionalmailersend

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mailersend-mailersend/health.svg)

```
[![Health](https://phpackages.com/badges/mailersend-mailersend/health.svg)](https://phpackages.com/packages/mailersend-mailersend)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[friendsofsymfony/http-cache

Tools to manage HTTP caching proxies with PHP

36114.7M36](/packages/friendsofsymfony-http-cache)[railsware/mailtrap-php

The Mailtrap SDK provides methods for all API functions.

56770.5k](/packages/railsware-mailtrap-php)[j0k3r/graby

Graby helps you extract article content from web pages

384349.6k2](/packages/j0k3r-graby)[mailersend/laravel-driver

MailerSend Laravel Driver

87732.8k4](/packages/mailersend-laravel-driver)

PHPackages © 2026

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