Laravel

Point Laravel's mailer at a sandbox with five environment variables — no package, no code change.

Before you start

  • PHP 8.1 or later
  • Laravel 9, 10, 11 or 12

1Set the mail variables

Laravel ships with an SMTP mailer, so there is nothing to install. Replace the mail block of your .env — keep the rest of the file as it is.

.env
# .env
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailclutch.com
MAIL_PORT=587
MAIL_USERNAME=mc_0000000000000000
MAIL_PASSWORD=pw_0000000000000000
MAIL_FROM_ADDRESS="staging@example.com"
MAIL_FROM_NAME="${APP_NAME}"

Then clear the cached config, or the old values will keep being used: php artisan config:clear.

2Send a test message

From a shell, with php artisan tinker:

Mail::raw('Hello from Laravel.', function ($message) {
    $message->to('anyone@example.com')->subject('Sandbox check');
});

Or run whatever already sends mail in your application — a password reset, an order confirmation. Nothing is delivered onward, so real addresses are safe.

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

  • Queued mail never arrives

    Anything sent through Mail::queue() or a ShouldQueue mailable waits for a worker. Run php artisan queue:work, or set QUEUE_CONNECTION=sync in staging.

  • Encryption

    Laravel 11 and 12 negotiate STARTTLS on port 587 by themselves. On Laravel 10 and earlier, add MAIL_ENCRYPTION=tls — or use port 465 with MAIL_ENCRYPTION=ssl.

Official documentationLaravel — Mail (opens in a new tab)