Laravel tries to send mail to mailpit:1025 instead of your real SMTP server
Connection could not be established with host "mailpit:1025"Short answer
Laravel is still using the development mail host from the starter .env, mailpit on port 1025, which only exists inside Laravel Sail. Your real values are not reaching the app: either .env was never changed, the config is cached, or a server-level variable overrides the file.
Fix it fast
1Find out which cause you have
Ask the running app which mail host it really uses. Do this in the same environment as the failing request, not on your laptop.
php artisan tinker --execute="dump(config('mail.mailers.smtp.host'), config('mail.mailers.smtp.port'));"2Match what you see, then jump to its fix
- 1
Tinker prints mailpit and 1025.The starter .env values were never replacedFix - 2
The .env file shows the new host, but tinker or the error still shows mailpit. A file bootstrap/cache/config.php exists.Configuration is cached, so the edited .env is not readFix - 3
Tinker still shows mailpit after config:clear, and .env is correct.A server-level environment variable overrides .envFix
- 1
What does the error look like?
Connection could not be established with host "mailpit:1025"Symfony\Component\Mailer\Exception\TransportException
Cause 1 of 3
The starter .env values were never replaced
1Check
The Laravel 10 starter .env.example ships MAIL_HOST=mailpit and MAIL_PORT=1025. That host name only resolves inside a Sail Docker network, so on shared hosting or a VPS it cannot be reached.
grep -n "^MAIL_" .env2Fix
Put the host, port and login your mail provider gave you into .env. Keep one MAIL_MAILER line only.
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your-login
MAIL_PASSWORD=your-app-password3Verify
Clear config, then read the values back in tinker.
php artisan config:clear
php artisan tinker --execute="dump(config('mail.mailers.smtp.host'));"Confirmed by raw.githubusercontent.com
Cause 2 of 3
Configuration is cached, so the edited .env is not read
1Check
After config:cache the framework no longer loads .env during requests or Artisan commands. It uses the cached array.
ls -l bootstrap/cache/config.php2Fix
Purge the cached configuration, and rebuild it only after .env is correct.
php artisan config:clear
php artisan config:cache3Verify
Tinker now prints the new host.
php artisan tinker --execute="dump(config('mail.mailers.smtp.host'));"Confirmed by laravel.com
Cause 3 of 3
A server-level environment variable overrides .env
1Check
Laravel allows any variable in .env to be overridden by an external server or system environment variable. Docker Compose files, PHP-FPM pool settings, a panel's environment screen and CI secrets are the usual places.
printenv | grep '^MAIL_'
grep -rn "MAIL_HOST" docker-compose*.yml /etc/php 2>/dev/null2Fix
Change or remove the MAIL_* variable where it is defined, then restart PHP-FPM, the container or the queue workers so they see it.
sudo systemctl restart php8.3-fpm
php artisan queue:restart3Verify
Tinker, run through the same process, prints the host you set.
php artisan tinker --execute="dump(config('mail.mailers.smtp.host'));"Confirmed by laravel.com
How do I stop it coming back?
- Replace every MAIL_* line when you copy .env.example to a server, not just the password.
- Run config:cache only as a deploy step, after .env is final.
- Keep mail settings in one place: either .env or the platform environment, not both.
- Restart queue workers after a mail setting changes, because they keep old config in memory.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Laravel says the email was sent, but nothing arrives
Mail::to($user)->send() returns normally
Mail::send returns without an error when the message was accepted by the configured mailer, not when it was delivered.
3 causes, each with a fixLaravel mail fails because an address does not comply with RFC 2822
Email "Jane Doe <jane@example.com>" does not comply with addr-spec of RFC 2822.
Symfony Mailer checks every address when the Address object is created.
3 causes, each with a fixLaravel mail fails with 'Unable to connect with STARTTLS' and SSL operation failed with code 1
stream_socket_enable_crypto(): Peer certificate verification failed
The mail server offered STARTTLS, but PHP could not verify the certificate it presented.
3 causes, each with a fixCodeIgniter email does not send and shows no error message
$email->printDebugger() prints an empty result
CodeIgniter signals a failed email only by send() returning false, with no exception.
4 causes, each with a fixPHP mail() returns true but the email never arrives
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing
mail() returning true only means the message was accepted for delivery, not that it arrived.
4 causes, each with a fixPHPMailer addCC() adds no CC recipient
The mail arrives for the To address but not for the CC address
addCC() returns false when it rejects the address, and PHPMailer then sends without that CC.
3 causes, each with a fix