1. Go to this page and download the library: Download lettermint/lettermint-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lettermint / lettermint-php example snippets
use Lettermint\Lettermint;
$lettermint = new Lettermint(sendingToken: getenv('LETTERMINT_PROJECT_TOKEN'));
$result = $lettermint->emails->send([
'from' => 'Acme <[email protected]>',
'to' => ['[email protected]'],
'subject' => 'Welcome to Acme',
'html' => '<p>Thanks for signing up.</p>',
'text' => 'Thanks for signing up.',
]);
echo $result->message_id, ' ', $result->status; // "…", "pending"
$lettermint = new Lettermint(
sendingToken: getenv('LETTERMINT_PROJECT_TOKEN'),
teamToken: getenv('LETTERMINT_TEAM_TOKEN'),
);
$lettermint = new Lettermint(getenv('LETTERMINT_TOKEN'));
$lettermint = new Lettermint(getenv('LETTERMINT_TOKEN'), timeout: 10);
$message = $lettermint->messages->retrieve('message-id');
echo $message->subject;
foreach ($message->to ?? [] as $recipient) {
echo $recipient->email;
}
$message['subject']; // array access works too
$message->toArray(); // the JSON as the API sent it
$message->has('spam_score'); // whether an optional field is present
$result = $lettermint->analytics([
'metrics' => ['delivered', 'bounced', 'delivery_rate'],
'from' => '2026-10-01',
'to' => '2026-10-31',
'timezone' => 'Europe/Amsterdam',
]);
var_dump($result->data->summary?->metrics->delivery_rate); // 0.9836, or null when there is no data
var_dump($result->meta->partial, $result->meta->effective_to);
$query = [
'metrics' => ['delivered', 'bounced'],
'tric' => 'bounced', 'direction' => 'desc'],
'limit' => 200,
];
$rows = [];
foreach ($lettermint->analyticsPages($query) as $page) {
array_push($rows, ...($page->data->breakdown ?? []));
if ($page->pagination->truncated) {
error_log('More groups exist than the API ranks.');
}
}
use Lettermint\Exceptions\ApiException;
use Lettermint\Exceptions\RateLimitException;
use Lettermint\Exceptions\TimeoutException;
use Lettermint\Exceptions\ValidationException;
try {
$lettermint->emails->send($message, idempotencyKey: $key);
} catch (ValidationException $e) {
report($e->getMessage(), $e->errors);
} catch (RateLimitException $e) {
sleep($e->retryAfter ?? 1); // then retry with the same idempotency key
} catch (TimeoutException $e) {
// The outcome is unknown. Retry with the same idempotency key.
} catch (ApiException $e) {
report($e->status, $e->errorCode, $e->getMessage());
}
use Lettermint\Exceptions\WebhookVerificationException;
use Lettermint\Webhook;
$webhook = new Webhook(getenv('LETTERMINT_WEBHOOK_SECRET'));
try {
$payload = $webhook->verify($request->getContent(), $request->headers);
} catch (WebhookVerificationException $e) {
return new Response('Invalid signature', 400);
}
echo $payload->event; // "message.delivered"
$payload->data; // the event data