Search by

emercurymail / smtp-sdk

roman-emercury

Official PHP SDK for the Emercury SMTP API

v2.0.0 2026-10-13 15:30 UTC

This package is auto-updated.

Last update: 2026-10-27 08:36:32 UTC


README

The official PHP client for sending transactional email and reading outbound delivery statistics through the stable Emercury SMTP API.

Requirements

  • PHP 8.1 or newer
  • cURL, JSON, and mbstring extensions

Installation

composer require emercurymail/smtp-sdk

Send an email

<?php

use Emercury\SmtpSdk\Api\EmailApi;
use Emercury\SmtpSdk\Configuration;
use Emercury\SmtpSdk\Model\EmailAddress;
use Emercury\SmtpSdk\Model\EmailContentPart;
use Emercury\SmtpSdk\Model\SendEmailRequest;
use GuzzleHttp\Client;

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

$configuration = Configuration::getDefaultConfiguration()
    ->setApiKey('X-Emercury-Token', getenv('EMERCURY_API_TOKEN'));

$email = new SendEmailRequest([
    'from' => new EmailAddress(['email' => 'sender@example.com', 'name' => 'Example']),
    'to' => [new EmailAddress(['email' => 'recipient@example.net'])],
    'subject' => 'Hello from Emercury',
    'contents' => [new EmailContentPart([
        'content_type' => 'text/plain',
        'content' => 'Your transactional email is ready.',
    ])],
]);

$result = (new EmailApi(new Client(), $configuration))->sendEmail(
    $email,
    idempotency_key: '01992ee0-31a6-783c-bd0d-2677ef418ee8',
);

foreach ($result->getData()->getMessages() as $message) {
    echo $message->getMessageId() . ' ' . $message->getTo() . PHP_EOL;
}

Use a unique idempotency key when a send may be retried. The same key and normalized payload return the original response for 24 hours; reusing a key with a different payload returns 409 Conflict.

Migrating from 1.x to 2.0

Wrap the previous to object in a non-empty array, even for a single recipient. Read queued messages from $result->getData()->getMessages() instead of $result->getData(). Each recipient receives a separate message with its own ID; the returned messages follow the order of to.

Version 2.0 requires the API changes in ES-25. Upgrade only after those changes are deployed to your API server.