Symfony

One DSN in .env.local sends every Symfony Mailer message to a sandbox.

Prerequisites

  • PHP 8.1 or later
  • symfony/mailer

1Install the mailer

Skip this if the component is already there.

composer require symfony/mailer

2Point the DSN at the sandbox

.env.local
# .env.local
MAILER_DSN=smtp://mc_0000000000000000:pw_0000000000000000@smtp.mailclutch.com:587

Keep it in .env.local rather than .env: the credentials are per environment, and that file is not committed.

3Send a test message

Symfony 6.2 and later
php bin/console mailer:test anyone@example.com

Or from your own code:

use Symfony\Component\Mime\Email;

$email = (new Email())
    ->from('staging@example.com')
    ->to('anyone@example.com')
    ->subject('Sandbox check')
    ->text('Hello from Symfony.');

$mailer->send($email);

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the sandbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The sandbox keeps what it catches for 24 hours.

Go further

  • Messenger routing

    If framework.messenger routes SendEmailMessage to a transport, mail leaves only when a consumer runs: php bin/console messenger:consume async.

  • MAILER_DSN in .env.local

    MAILER_DSN=null://null in .env.local or .env.dev wins over .env, and every message is dropped silently. Check those files when nothing shows up here.

Official documentationSymfony — Sending Emails (opens in a new tab)