Skip to content

Latest commit

Β 

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Elastic Email

Elastic Email PHP SDK

The official PHP client library for the Elastic Email REST API v4.

Packagist Packagist downloads PHP API OpenAPI Generator License: MIT

Latest release Last commit Open issues GitHub stars

Installation β€’ Quick start β€’ Examples β€’ API reference β€’ Models β€’ Contributing


Features

  • Transactional and bulk email. Send single messages, bulk campaigns or CSV merge-file sends.
  • Contacts, lists and segments. Add, update, import, export and bulk-delete contacts.
  • Campaigns and automations. Create, update, pause and trigger automations for a contact.
  • Templates, files and attachments. Manage templates and uploaded files.
  • Domains. Verify sending domains and check SPF, DKIM, tracking and certificate status.
  • Webhooks and inbound routes. Receive delivery events and route incoming mail.
  • Statistics, events and suppressions. Track delivery, bounces, complaints and unsubscribes.
  • Subaccounts and security. Manage subaccounts and API keys.
  • Sync and async. Every endpoint has a blocking method and an …Async method that returns a Guzzle promise.

Requirements

Requirement Version
PHP 7.4 or later (PHP 8.x supported)
Extensions curl, json, mbstring
HTTP client Guzzle 7.3 or later

You'll also need an Elastic Email API key. You can create one in your API settings. Each endpoint's documentation lists the access level it needs.

Installation

Install the elasticemail/elasticemail-php package from Packagist with Composer:

composer require elasticemail/elasticemail-php

Or add it to your composer.json:

{
  "require": {
    "elasticemail/elasticemail-php": "^4.2"
  }
}

Composer installs the dependencies (guzzlehttp/guzzle and guzzlehttp/psr7) for you. Then load Composer's autoloader:

require_once __DIR__ . '/vendor/autoload.php';

Quick start

Important

Elastic Email only sends from verified domains. Before your first send, verify your sending domain and use an address on that domain as the sender.

Configure the client

<?php
require_once __DIR__ . '/vendor/autoload.php';

use ElasticEmail\Api\EmailsApi;
use ElasticEmail\ApiException;
use ElasticEmail\Configuration;
use ElasticEmail\Model;

$config = Configuration::getDefaultConfiguration()
    ->setApiKey('X-ElasticEmail-ApiKey', getenv('ELASTICEMAIL_API_KEY'));

Tip

Keep your API key out of source code. Load it from an environment variable, a .env file kept out of version control or a secrets manager.

Send a transactional email

$emails = new EmailsApi(new GuzzleHttp\Client(), $config);

$message = new Model\EmailTransactionalMessageData([
    'recipients' => new Model\TransactionalRecipient([
        'to' => ['john.doe@example.com'],
    ]),
    'content' => new Model\EmailContent([
        'from' => 'My App <no-reply@yourdomain.com>',
        'subject' => 'Welcome aboard!',
        'body' => [
            new Model\BodyPart([
                'content_type' => Model\BodyContentType::HTML,
                'content' => '<h1>Hello!</h1><p>Thanks for signing up.</p>',
            ]),
            new Model\BodyPart([
                'content_type' => Model\BodyContentType::PLAIN_TEXT,
                'content' => 'Hello! Thanks for signing up.',
            ]),
        ],
    ]),
]);

try {
    $result = $emails->emailsTransactionalPost($message);
    echo "Sent. TransactionID: {$result->getTransactionId()}, MessageID: {$result->getMessageId()}", PHP_EOL;
} catch (ApiException $e) {
    echo "Elastic Email API error {$e->getCode()}: {$e->getMessage()}", PHP_EOL;
}

The from address must use a domain you've verified in your Elastic Email account.

Send from a template with merge fields

$message = new Model\EmailTransactionalMessageData([
    'recipients' => new Model\TransactionalRecipient([
        'to' => ['john.doe@example.com'],
    ]),
    'content' => new Model\EmailContent([
        'from' => 'My App <no-reply@yourdomain.com>',
        'template_name' => 'welcome-template',
        'merge' => ['firstname' => 'John'],
    ]),
]);

$emails->emailsTransactionalPost($message);

Using a proxy

Pass any Guzzle options, such as a proxy or timeouts, to the HTTP client:

$client = new GuzzleHttp\Client([
    'proxy' => 'http://myProxyUrl:80/',
    'timeout' => 600,
]);

$emails = new EmailsApi($client, $config);

More examples

More complete, runnable samples are in the Elastic Email examples repository. It covers transactional email, SMTP, webhooks, inbound email, contacts and serverless platforms across 20+ languages and frameworks.

This repository also includes short snippets for common tasks in examples/functions:

Show snippets
Snippet Description
addBulkContacts readme
addCampaign readme
addList readme
addSingleContact readme
addTemplate readme
deleteCampaign readme
deleteContact readme
deleteList readme
exportContacts readme
loadCampaign readme
loadCampaigns readme
loadCampaignsStats readme
loadChannelsStats readme
loadList readme
loadStatistics readme
loadTemplate readme
sendBulkEmails readme
sendTransactionalEmails readme
updateCampaign readme

Authentication

Scheme Header Used for
apikey X-ElasticEmail-ApiKey All standard API calls
ApiKeyAuthCustomBranding X-Auth-Token Custom-branding (white-label) accounts

API limits

  • Up to 20 concurrent connections per account
  • A hard timeout of 600 seconds per request

API reference

All URIs are relative to https://api.elasticemail.com/v4. The SDK covers 114 endpoints across 16 API classes: CampaignsApi, ContactsApi, DomainsApi, EmailsApi, EventsApi, FilesApi, InboundRouteApi, ListsApi, SecurityApi, SegmentsApi, StatisticsApi, SubAccountsApi, SuppressionsApi, TemplatesApi, VerificationsApi and WebhookApi.

Show all endpoints
Class Method HTTP request Description
CampaignsApi campaignsAutomationByNameTriggerPost POST /campaigns/automation/{name}/trigger Trigger Automation for Contact
CampaignsApi campaignsByNameDelete DELETE /campaigns/{name} Delete Campaign
CampaignsApi campaignsByNameGet GET /campaigns/{name} Load Campaign
CampaignsApi campaignsByNamePausePut PUT /campaigns/{name}/pause Pause Campaign
CampaignsApi campaignsByNamePut PUT /campaigns/{name} Update Campaign
CampaignsApi campaignsGet GET /campaigns Load Campaigns
CampaignsApi campaignsPost POST /campaigns Add Campaign
ContactsApi contactsByEmailDelete DELETE /contacts/{email} Delete Contact
ContactsApi contactsByEmailGet GET /contacts/{email} Load Contact
ContactsApi contactsByEmailPut PUT /contacts/{email} Update Contact
ContactsApi contactsDeletePost POST /contacts/delete Delete Contacts Bulk
ContactsApi contactsExportByIdStatusGet GET /contacts/export/{id}/status Check Export Status
ContactsApi contactsExportPost POST /contacts/export Export Contacts
ContactsApi contactsGet GET /contacts Load Contacts
ContactsApi contactsImportPost POST /contacts/import Upload Contacts
ContactsApi contactsPost POST /contacts Add Contact
DomainsApi domainsByDomainDelete DELETE /domains/{domain} Delete Domain
DomainsApi domainsByDomainGet GET /domains/{domain} Load Domain
DomainsApi domainsByDomainPut PUT /domains/{domain} Update Domain
DomainsApi domainsByDomainRestrictedGet GET /domains/{domain}/restricted Check for domain restriction
DomainsApi domainsByDomainVerificationPut PUT /domains/{domain}/verification Verify Domain
DomainsApi domainsByEmailDefaultPatch PATCH /domains/{email}/default Set Default
DomainsApi domainsGet GET /domains Load Domains
DomainsApi domainsPost POST /domains Add Domain
EmailsApi emailsByMsgidViewGet GET /emails/{msgid}/view View Email
EmailsApi emailsByTransactionidStatusGet GET /emails/{transactionid}/status Get Status
EmailsApi emailsMergefilePost POST /emails/mergefile Send Bulk Emails CSV
EmailsApi emailsPost POST /emails Send Bulk Emails
EmailsApi emailsTransactionalPost POST /emails/transactional Send Transactional Email
EventsApi eventsByTransactionidGet GET /events/{transactionid} Load Email Events
EventsApi eventsChannelsByNameExportPost POST /events/channels/{name}/export Export Channel Events
EventsApi eventsChannelsByNameGet GET /events/channels/{name} Load Channel Events
EventsApi eventsChannelsExportByIdStatusGet GET /events/channels/export/{id}/status Check Channel Export Status
EventsApi eventsExportByIdStatusGet GET /events/export/{id}/status Check Export Status
EventsApi eventsExportPost POST /events/export Export Events
EventsApi eventsGet GET /events Load Events
FilesApi filesByNameDelete DELETE /files/{name} Delete File
FilesApi filesByNameGet GET /files/{name} Download File
FilesApi filesByNameInfoGet GET /files/{name}/info Load File Details
FilesApi filesGet GET /files List Files
FilesApi filesPost POST /files Upload File
InboundRouteApi inboundrouteByIdDelete DELETE /inboundroute/{id} Delete Route
InboundRouteApi inboundrouteByIdGet GET /inboundroute/{id} Get Route
InboundRouteApi inboundrouteByIdPut PUT /inboundroute/{id} Update Route
InboundRouteApi inboundrouteGet GET /inboundroute Get Routes
InboundRouteApi inboundrouteOrderPut PUT /inboundroute/order Update Sorting
InboundRouteApi inboundroutePost POST /inboundroute Create Route
ListsApi listsByListnameContactsGet GET /lists/{listname}/contacts Load Contacts in List
ListsApi listsByNameContactsPost POST /lists/{name}/contacts Add Contacts to List
ListsApi listsByNameContactsRemovePost POST /lists/{name}/contacts/remove Remove Contacts from List
ListsApi listsByNameDelete DELETE /lists/{name} Delete List
ListsApi listsByNameGet GET /lists/{name} Load List
ListsApi listsByNamePut PUT /lists/{name} Update List
ListsApi listsGet GET /lists Load Lists
ListsApi listsPost POST /lists Add List
SecurityApi securityApikeysByNameDelete DELETE /security/apikeys/{name} Delete ApiKey
SecurityApi securityApikeysByNameGet GET /security/apikeys/{name} Load ApiKey
SecurityApi securityApikeysByNamePut PUT /security/apikeys/{name} Update ApiKey
SecurityApi securityApikeysGet GET /security/apikeys List ApiKeys
SecurityApi securityApikeysPost POST /security/apikeys Add ApiKey
SecurityApi securitySmtpByNameDelete DELETE /security/smtp/{name} Delete SMTP Credential
SecurityApi securitySmtpByNameGet GET /security/smtp/{name} Load SMTP Credential
SecurityApi securitySmtpByNamePut PUT /security/smtp/{name} Update SMTP Credential
SecurityApi securitySmtpGet GET /security/smtp List SMTP Credentials
SecurityApi securitySmtpPost POST /security/smtp Add SMTP Credential
SegmentsApi segmentsByNameDelete DELETE /segments/{name} Delete Segment
SegmentsApi segmentsByNameGet GET /segments/{name} Load Segment
SegmentsApi segmentsByNamePut PUT /segments/{name} Update Segment
SegmentsApi segmentsGet GET /segments Load Segments
SegmentsApi segmentsPost POST /segments Add Segment
StatisticsApi statisticsCampaignsByNameGet GET /statistics/campaigns/{name} Load Campaign Stats
StatisticsApi statisticsCampaignsGet GET /statistics/campaigns Load Campaigns Stats
StatisticsApi statisticsChannelsByNameGet GET /statistics/channels/{name} Load Channel Stats
StatisticsApi statisticsChannelsGet GET /statistics/channels Load Channels Stats
StatisticsApi statisticsGet GET /statistics Load Statistics
SubAccountsApi subaccountsByEmailApikeyGet GET /subaccounts/{email}/apikey Get SubAccount ApiKey
SubAccountsApi subaccountsByEmailCreditsPatch PATCH /subaccounts/{email}/credits Add, Subtract Email Credits
SubAccountsApi subaccountsByEmailDelete DELETE /subaccounts/{email} Delete SubAccount
SubAccountsApi subaccountsByEmailGet GET /subaccounts/{email} Load SubAccount
SubAccountsApi subaccountsByEmailSettingsEmailPut PUT /subaccounts/{email}/settings/email Update SubAccount Email Settings
SubAccountsApi subaccountsGet GET /subaccounts Load SubAccounts
SubAccountsApi subaccountsPost POST /subaccounts Add SubAccount
SuppressionsApi suppressionsBouncesGet GET /suppressions/bounces Get Bounce List
SuppressionsApi suppressionsBouncesImportPost POST /suppressions/bounces/import Add Bounces Async
SuppressionsApi suppressionsBouncesPost POST /suppressions/bounces Add Bounces
SuppressionsApi suppressionsByEmailDelete DELETE /suppressions/{email} Delete Suppression
SuppressionsApi suppressionsByEmailGet GET /suppressions/{email} Get Suppression
SuppressionsApi suppressionsComplaintsGet GET /suppressions/complaints Get Complaints List
SuppressionsApi suppressionsComplaintsImportPost POST /suppressions/complaints/import Add Complaints Async
SuppressionsApi suppressionsComplaintsPost POST /suppressions/complaints Add Complaints
SuppressionsApi suppressionsGet GET /suppressions Get Suppressions
SuppressionsApi suppressionsUnsubscribesGet GET /suppressions/unsubscribes Get Unsubscribes List
SuppressionsApi suppressionsUnsubscribesImportPost POST /suppressions/unsubscribes/import Add Unsubscribes Async
SuppressionsApi suppressionsUnsubscribesPost POST /suppressions/unsubscribes Add Unsubscribes
TemplatesApi templatesByNameDelete DELETE /templates/{name} Delete Template
TemplatesApi templatesByNameGet GET /templates/{name} Load Template
TemplatesApi templatesByNamePut PUT /templates/{name} Update Template
TemplatesApi templatesGet GET /templates Load Templates
TemplatesApi templatesPost POST /templates Add Template
VerificationsApi verificationsByEmailDelete DELETE /verifications/{email} Delete Email Verification Result
VerificationsApi verificationsByEmailGet GET /verifications/{email} Get Email Verification Result
VerificationsApi verificationsByEmailPost POST /verifications/{email} Verify Email
VerificationsApi verificationsFilesByIdDelete DELETE /verifications/files/{id} Delete File Verification Result
VerificationsApi verificationsFilesByIdResultDownloadGet GET /verifications/files/{id}/result/download Download File Verification Result
VerificationsApi verificationsFilesByIdResultGet GET /verifications/files/{id}/result Get Detailed File Verification Result
VerificationsApi verificationsFilesByIdVerificationPost POST /verifications/files/{id}/verification Start verification
VerificationsApi verificationsFilesPost POST /verifications/files Upload File with Emails
VerificationsApi verificationsFilesResultGet GET /verifications/files/result Get Files Verification Results
VerificationsApi verificationsGet GET /verifications Get Emails Verification Results
WebhookApi webhookByPublicidDelete DELETE /webhook/{publicid} Delete Webhook
WebhookApi webhookByPublicidGet GET /webhook/{publicid} Load Webhook
WebhookApi webhookByPublicidPut PUT /webhook/{publicid} Update Webhook
WebhookApi webhookGet GET /webhook Load Webhooks
WebhookApi webhookPost POST /webhook Add Webhook

Models

Show all 98 models

Tests

composer install
vendor/bin/phpunit

Versioning

The SDK follows the Elastic Email API v4. Package versions and release notes are listed on Packagist and in GitHub Releases.

Build details
  • API version: 4.0.0
  • SDK version: 4.2.0
  • Generator version: 7.11.0
  • Build package: org.openapitools.codegen.languages.PhpClientCodegen

Contributing

Contributions are welcome! Most of this SDK is generated from the Elastic Email OpenAPI specification by OpenAPI Generator, so please read CONTRIBUTING.md before opening a pull request.

This project follows the Contributor Covenant Code of Conduct.

Support

Important

The fastest way to get help is the chat widget on elasticemail.com. Our support team can help with your account, sending, deliverability and API questions.

License

Released under the MIT License. Copyright Β© 2021–2026 Elastic Email.

About

Official PHP SDK for the Elastic Email REST API v4. Send transactional and marketing emails, and manage contacts, lists, templates, campaigns, domains and webhooks. Available on Packagist.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

14 stars

Watchers

4 watching

Forks

Releases

Used by

Contributors

Languages