Sendery
Sendery

Language SDKs

PHP

Send published Sendery templates from PHP.

Install
composer require sendery/php:^0.1
Source code

Requirements

PHP 8.3+ with the cURL extension.

Set up

Publish a welcome template with name and action_url variables, and create a project API key. Store it as SENDERY_API_KEY on your server.

Shell
export SENDERY_API_KEY="your_project_api_key"

Send an email

The response contains the accepted email’s id and status. For a template without variables, pass data: []; the SDK sends an empty JSON object.

PHP
require 'vendor/autoload.php';

use Sendery\Client;

$sendery = new Client(getenv('SENDERY_API_KEY'));
$receipt = $sendery->send(
    to: '[email protected]',
    template: 'welcome',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
);

echo $receipt['id'];

Retrieve an email

Use the returned ID to check delivery status.

PHP
$message = $sendery->get($receipt['id']);
echo $message['status'];

Retry a send

Use a key such as welcome-123 for one email, and keep the payload unchanged on retries. retry(3) allows up to three additional attempts for temporary failures; send() alone makes one attempt.

PHP
$email = $sendery->prepare(
    to: '[email protected]',
    template: 'welcome',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
    idempotencyKey: 'welcome-123',
);
$receipt = $email->retry(3)->send();

Handle errors

Catch the SDK exception to inspect the status and code. Retry delays are in seconds. The example uses the prepared $email from the retry example above.

PHP
try {
    $receipt = $email->retry(3)->send();
} catch (\Sendery\ApiException $error) {
    error_log($error->status.': '.$error->errorCode);
    // $error->errors contains field-level validation errors.
    // $error->retryAfter is a delay in seconds, when provided.
    throw $error;
}