PHP
Use the official PHP SDK with PHP 8.3 or later and Composer.
Before you start
You need a verified sending domain and an API key with the sending scope. Set EPOSTIX_API_KEY in your environment.
Install
composer require epostix/sdk-php guzzlehttp/guzzle
The SDK uses a PSR-18 HTTP client and PSR-17 factories. Guzzle supplies them for this example; an application that already has compatible implementations can use those.
Send an email
Replace the sender with an address at your verified domain and the recipient with your own address.
<?php
require 'vendor/autoload.php';
use Epostix\Client;
use Epostix\EpostixApiError;
use Epostix\Generated\EmailCreate;
$client = new Client(getenv('EPOSTIX_API_KEY') ?: '');
try {
$email = $client->emails->sendEmail(new EmailCreate(
subject: 'Your first email',
html: '<p>Sent with Epostix.</p>',
text: 'Sent with Epostix.',
), idempotencyKey: 'first-email-001');
echo $email->id . PHP_EOL;
} catch (EpostixApiError $error) {
error_log($error->type . ' request_id=' . $error->requestId);
throw $error;
}
php send.php
The returned ID means the message was accepted. Follow it in Activity or use webhooks to record delivery.
Make retries safe
The SDK retries eligible transient failures within a bounded deadline. Pass the same idempotencyKey for every attempt of the same logical send. A queue job should derive it from a stored event or order ID.
Running this example twice with the same API key and body returns the first result within 24 hours. Choose a new key for a new email. See idempotency.
Next
- Laravel for framework configuration
- Test mode to simulate delivery
- SMTP credentials for an existing mailer