Search by

sendery / php

ncaroyannis

Sendery php template email SDK

v0.1.4 2026-10-02 03:58 UTC

This package is auto-updated.

Last update: 2026-10-02 03:59:02 UTC


README

Send published Sendery templates from PHP.

Documentation · API reference · Changelog

Requirements

PHP 8.3+ with the cURL extension.

Install

composer require sendery/php:^0.1.1

Set up

Choose a published template and create a project API key. Store the key as SENDERY_API_KEY on your server.

export SENDERY_API_KEY="your_project_api_key"

Send an email

Replace your-template with your published template’s key and data with its variables.

The response contains the email’s id and status. If your template has no variables, pass data: [].

require 'vendor/autoload.php';

use Sendery\Client;

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

echo $receipt['id'];

Send a specific version

Choose a published template version to keep sending it after newer versions are published. By default, Sendery uses the latest version.

$receipt = $sendery->prepare(
    to: 'alex@example.com',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
)->version(3)->send();

Attachments

Pass files through attachments. Use Attachment::fromPath() for a local file, or new Attachment() for file contents you already have.

Send up to 10 files totaling 5 MB. See the attachment reference for supported formats and limits.

use Sendery\Attachment;

$sendery->prepare(
    to: 'alex@example.com',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
    idempotencyKey: 'your-idempotency-key',
    attachments: [
        Attachment::fromPath('/path/document.pdf', 'document.pdf', 'application/pdf'),
    ],
)->retry()->send();

Retrieve an email

Use the returned ID to check delivery status.

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

Retry a send

Use retry(3) for up to three extra attempts after temporary failures. Keep the same idempotency key and email data on every attempt.

$email = $sendery->prepare(
    to: 'alex@example.com',
    template: 'your-template',
    data: ['name' => 'Alex', 'action_url' => 'https://example.com/start'],
    idempotencyKey: 'your-idempotency-key',
);
$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.

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;
}

More

Learn how to retry emails without duplicate sends.

License

MIT.