How to Use Mailpit with Symfony and Laravel in Docker Compose
Sooner or later, someone testing a "forgot password" flow locally sends a real password-reset email to a real customer, because the dev environment was quietly configured to use the production SMTP credentials. Mailpit exists to make that impossible: it's a fake SMTP server that catches every outgoing email and shows it in a web UI instead of delivering it anywhere.
1. Add the Mailpit service
services:
mailpit:
image: axllent/mailpit
ports:
- "1025:1025"
- "8025:8025"Port 1025 is the SMTP port your application sends to. Port 8025 is the web UI — open http://localhost:8025 and every email your app sends will show up there, instantly, with full headers and both HTML/plain-text bodies.
2. Symfony: point Mailer at it
# .env MAILER_DSN=smtp://mailpit:1025
That's the whole configuration. No username, no password, no TLS — Mailpit doesn't authenticate anything, it accepts whatever is sent to it. Note the host is mailpit (the Compose service name), not localhost — see how to connect PHP to Redis for why that distinction matters for every service in a Compose stack, not just Redis.
3. Laravel: point Mail at it
# .env MAIL_MAILER=smtp MAIL_HOST=mailpit MAIL_PORT=1025 MAIL_USERNAME=null MAIL_ENCRYPTION=null
Leave MAIL_USERNAME and MAIL_PASSWORD empty or null — if you copy these lines from a production .env.example that has real placeholder-looking values, Laravel will still try to authenticate with them and the send will fail even though Mailpit doesn't care about credentials at all.
4. Send a test email and verify
Symfony:
php bin/console mailer:test someone@example.com
Laravel:
php artisan tinker
>>> Mail::raw('test', fn ($m) => $m->to('someone@example.com')->subject('test'));Then check http://localhost:8025 — the message should appear within a second, with no real email ever leaving your machine.
Common pitfall: framework validation rejecting a fake domain
Some form/validation rules check that an email address's domain has valid DNS records. If you're testing with addresses like test@test.local, that validation can reject them even though Mailpit itself doesn't care — use a real-looking domain (e.g. test@example.com) for local testing to sidestep this entirely.
Generate a ready-to-run Docker Compose setup for your stack — compose.yml, nginx config, .env, and a README, in seconds.
Open the generator →