MailerSend PHP SDK
- Installation
- Usage
- Email API
- Bulk emails API
- Inbound routing
- Activity API
- Analytics API
- Domains API
- Messages API
- Scheduled messages API
- Tokens API
- Recipients API
- Webhooks API
- Templates API
- Email Verification API
- SMS API
- SMS phone number API
- SMS messages API
- SMS Activity API
- SMS Recipients API
- SMS webhooks API
- SMS inbound routing API
- Sender Identities
- SMTP Users
- Users
- Other endpoints
- Debugging validation errors
- Testing
- Support and Feedback
- License
- PHP 7.4
- PSR-7 and PSR-18 based HTTP adapter
- An API Key from mailersend.com
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 and 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']);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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('[email protected]', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->setFromName('Your Name')
->setRecipients($recipients)
->setSubject('Subject')
->setText('This is the text content');
$mailersend->email->send($emailParams);
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('[email protected]', 'Your Client'),
];
$cc = [
new Recipient('[email protected]', 'CC'),
];
$bcc = [
new Recipient('[email protected]', 'BCC'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$tags = ['tag'];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->setFromName('Your Name')
->setRecipients($recipients)
->setSubject('Subject')
->setTemplateId('ss243wdasd')
->setTags($tags);
$mailersend->email->send($emailParams);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Personalization;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$personalization = [
new Personalization('[email protected]', [
'var' => 'variable',
'number' => 123,
'object' => [
'key' => 'object-value'
],
'objectCollection' => [
[
'name' => 'John'
],
[
'name' => 'Patrick'
]
],
])
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Attachment;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$attachments = [
new Attachment(file_get_contents('attachment.jpg'), 'attachment.jpg')
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$recipients = [
new Recipient('[email protected]', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
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('[email protected]', 'Your Client'),
];
$headers = [
new Header('Custom-Header-1', 'Value 1')
new Header('Custom-Header-2', 'Value 2')
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\EmailParams;
$mailersend = new MailerSend();
$bulkEmailParams = [];
$bulkEmailParams[] = (new EmailParams())
->setFrom('[email protected]')
->setFromName('Your Name')
->setRecipients([
new Recipient('[email protected]', 'Your Client'),
])
->setSubject('Subject')
->setHtml('This is the HTML content')
->setText('This is the text content');
$bulkEmailParams[] = (new EmailParams())
->setFrom('[email protected]')
->setFromName('Your Name')
->setRecipients([
new Recipient('[email protected]', 'Your Client'),
])
->setSubject('Subject')
->setHtml('This is the HTML content')
->setText('This is the text content');
$mailersend->bulkEmail->send($bulkEmailParams);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->bulkEmail->getStatus('bulk_email_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->inbound->getAll($domainId = 'domainId', $page = 1, $limit = 10);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->inbound->find('inboundId');
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, '[email protected]'))))
->setMatchFilter(
(new MatchFilter(Constants::TYPE_MATCH_SENDER))
->addFilter(new Filter(Constants::COMPARER_EQUAL, '[email protected]', 'sender')))
->addForward(new Forward(Constants::COMPARER_EQUAL, 'value'))
);
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' => '[email protected]',
]
])
)
->setMatchFilter(
(new MatchFilter(Constants::TYPE_MATCH_SENDER))
->setFilters([
[
'comparer' => Constants::COMPARER_EQUAL,
'value' => '[email protected]',
'key' => 'sender',
]
])
)
->addForward(new Forward(Constants::COMPARER_EQUAL, 'value'))
);
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' => '[email protected]',
],
],
])
->setMatchFilter([
'type' => Constants::TYPE_MATCH_SENDER,
'filters' => [
[
'comparer' => Constants::COMPARER_EQUAL,
'value' => '[email protected]',
'key' => 'sender',
],
],
])
->setForwards([
[
'type' => Constants::COMPARER_EQUAL,
'value' => 'value',
]
])
);
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::COMPARER_EQUAL, 'value'))
);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->inbound->delete('inboundId');
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);
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\ActivityParams;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->activity->find('activity_id');
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);
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);
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);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->domain->getAll($page = 1, $limit = 10, $verified = true);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->domain->find('domain_id');
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->domain->delete('domain_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->domain->recipients($domainId = 'domain_id', $page = 1, $limit = 10);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->domain->verify('domain_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->domain->getDnsRecords('domain_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->messages->get($limit = 100, $page = 3);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->messages->find('message_id');
use MailerSend\MailerSend;
use \MailerSend\Common\Constants;
$mailersend = new MailerSend();
$mailersend->scheduleMessages->getAll(
'domain_id',
Constants::STATUS_SCHEDULED,
$limit = 100,
$page = 3
)
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->scheduleMessages->find('message_id');
use MailerSend\MailerSend;
use \MailerSend\Common\Constants;
$mailersend = new MailerSend();
$mailersend->scheduleMessages->delete('message_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->token->getAll($page = 1, $limit = 10);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->token->find('token_id');
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'];
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;
$mailersend = new MailerSend();
$mailersend->token->changeName('token_id', 'new name');
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
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\TokenParams;
$mailersend = new MailerSend();
$mailersend->token->delete('token_id');
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->recipients->find('recipient_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->recipients->delete('recipient_id');
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);
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);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->webhooks->get('domain_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->webhooks->find('webhook_id');
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)
);
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);
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.
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->template->find('template_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->template->delete('template_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->emailVerification->getAll($page = 1, $limit = 10);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->emailVerification->find('email_verification_id');
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\EmailVerificationParams;
$mailersend = new MailerSend();
$emailVerificationParams = (new EmailVerificationParams('file.csv'))
->setEmailAddresses(['[email protected]']);
$mailersend->emailVerification->create($emailVerificationParams);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->emailVerification->verify('email_verification_id');
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,
],
);
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);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$sms = $mailersend->smsNumber->getAll($page = 1, $limit = 10, $paused = true);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$sms = $mailersend->smsNumber->find('sms_number_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$sms = $mailersend->smsNumber->update('sms_number_id', $paused = true);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$sms = $mailersend->smsNumber->delete('sms_number_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsMessages = $mailersend->smsMessage->getAll($page = 1, $limit = 10);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsMessage = $mailersend->smsMessage->find('sms_message_id');
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);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsRecipient->find('sms_recipient_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsRecipient->update('sms_recipient_id', $status = 'opt_out');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsWebhook->get('sms_number_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsWebhook->find('sms_webhook_id');
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);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsInbound->getAll($smsNumberId = 'sms_number_id', $enabled = true, $page = 3, $limit = 15);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsInbound->find('sms_inbound_id');
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);
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);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$smsRecipients = $mailersend->smsInbound->delete('sms_inbound_id');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->senderIdentity->getAll($domainId = 'domainId', $page = 1, $limit = 10);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->senderIdentity->find('identityId');
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->senderIdentity->findByEmail('email');
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("[email protected]"))
->setAddNote(true)
->setPersonalNote("Hi John, please use this token")
);
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("[email protected]"))
->setAddNote(true)
->setPersonalNote("Hi John, please use this token")
);
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("[email protected]"))
->setAddNote(true)
->setPersonalNote("Hi John, please use this token")
);
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->senderIdentity->delete('identityId');
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->senderIdentity->deleteByEmail('email');
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->smtpUser->getAll('domainId', 25);
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->smtpUser->find('domainId', 'smtpUserId');
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)
);
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)
);
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->smtpUser->delete('domainId', 'smtpUserId');
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->user->getAll();
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->user->find('userId');
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)
);
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)
);
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->user->delete('userId');
<a name="get-a-list-of-invites>
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->invite->getAll();
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->invite->find('inviteId');
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->invite->resend('inviteId');
<a name="cancel-an-invite>
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->invite->cancel('inviteId');
use MailerSend\MailerSend;
$mailersend = new MailerSend();
$mailersend->apiQuota->get();
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('[email protected]', 'Your Client'),
];
$emailParams = (new EmailParams())
->setFrom('[email protected]')
->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());
}
composer test
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 [email protected]
The official documentation is at https://developers.mailersend.com