Symfony

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

Before you start

  • 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 inbox with an account and it stays.

Awaiting your email

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

What usually goes wrong

  • Messenger holds the message

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

  • Special characters in the DSN

    The username and password are URL-encoded inside the DSN. Ours are base32, so nothing needs escaping — but a hand-written password with @ or / does.

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