Sendery
Sendery

Framework Integrations

Symfony integration

Send transactional email with Sendery templates through Symfony Mailer.

Install
composer require sendery/symfony:^0.1.4
Source code

Requirements

Symfony Mailer 7.4 and PHP 8.3+ with the cURL extension.

Register the transport

Create a project API key and register the transport in config/services.yaml.

YAML
# config/services.yaml — add to your existing services section.
services:
  Sendery\Symfony\SenderyTransportFactory:
    tags: ['mailer.transport_factory']

Set the API key

Set MAILER_DSN in .env.local or your hosting provider’s secret settings.

.env.local
MAILER_DSN=sendery://[email protected]

Configure Mailer

Use the DSN in your existing Mailer configuration.

YAML
# config/packages/mailer.yaml
framework:
  mailer:
    dsn: '%env(MAILER_DSN)%'

Send an email

Pass the recipient, your published template’s key, and its variables to this service. Set from() to your project’s sender address.

PHP
use Sendery\Symfony\TemplateEmail;
use Symfony\Component\Mailer\MailerInterface;

final class TemplateEmails
{
    public function __construct(private MailerInterface $mailer) {}

    public function send(string $address, string $template, array $data): void
    {
        $email = (new TemplateEmail())
            ->from('[email protected]')
            ->to($address)
            ->template($template, $data);

        $this->mailer->send($email);
    }
}

Send with Messenger

With Symfony Messenger and your chosen transport installed, set MESSENGER_TRANSPORT_DSN and route mail to async. Run php bin/console messenger:consume async. The same queued TemplateEmail keeps its key and variables on retries.

YAML
# config/packages/messenger.yaml
framework:
  messenger:
    transports:
      async: '%env(MESSENGER_TRANSPORT_DSN)%'
    routing:
      'Symfony\Component\Mailer\Messenger\SendEmailMessage': async

Handle failures

A failed send throws TransportException. If you use Messenger, retry temporary failures with the same email. Fix API key, template, or billing errors before trying again.

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.

PHP
use Sendery\Symfony\TemplateEmail;

$email = (new TemplateEmail())
    ->from('[email protected]')
    ->to('[email protected]')
    ->template('your-template', [
        'name' => 'Alex',
        'action_url' => 'https://example.com/start',
    ])
    ->version(3);

$mailer->send($email);

Attachments

Attach files to TemplateEmail with Symfony’s attach() method.

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

Example
use Sendery\Symfony\TemplateEmail;

$email = (new TemplateEmail())
    ->from('[email protected]')
    ->to('[email protected]')
    ->template('your-template', [
        'name' => 'Alex',
        'action_url' => 'https://example.com/start',
    ], idempotencyKey: 'your-idempotency-key')
    ->attach(file_get_contents('/path/document.pdf'), 'document.pdf', 'application/pdf');

$mailer->send($email);