Laravel: Connection could not be established with host Email / SMTP Origin: Network Last updated 4 Nov 2026

Laravel: Symfony\Component\Mailer\Exception\TransportException: Connection could not be established with host "smtp.mailtrap.io:2525": stream_socket_client(): Unable to connect

Laravel's mailer could not connect to the SMTP host configured in .env.

Exact message you may see Connection could not be established with hostSymfony\Component\Mailer\Exception\TransportException: Connection could not be established with hostSwift_TransportException: Connection could not be established with hoststream_socket_client(): Unable to connect to ssl://smtpConnection refused #111 mailer
Seen on: SMTP Laravel PHP

Meaning

Check MAIL_MAILER, MAIL_HOST, MAIL_PORT, MAIL_ENCRYPTION and credentials, then clear the config cache — php artisan config:clear — because .env changes are ignored while config is cached. Also confirm the server can reach the host/port (firewall, DNS).

Common causes

  • Wrong MAIL_HOST or MAIL_PORT in .env
  • Config cached, so new .env values are ignored
  • Outbound SMTP port blocked on the server
  • Wrong encryption (tls vs ssl)
  • DNS resolution failing on the host

⚡ Quick fix

  1. Run php artisan config:clear after editing .env
  2. Verify values: php artisan tinker → config('mail')
  3. Test the port with nc -vz host port

Detailed fix by platform

Laravel

  1. php artisan config:clear && php artisan cache:clear then retry

Code examples

.env for SMTP

ini
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=user@example.com
MAIL_PASSWORD=app-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@example.com

How to diagnose

  1. Config — config('mail') shows expected values?
  2. Cache — config cached?
  3. Network — Port reachable?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Network. Errors that are often confused with or caused by this one (click to open):

419 Page Expired — Laravel: 419 Page Expired (CSRF token mismatch) (PHP)419 Page Expired421 4.7.0 Try again later (rate limited) — SMTP: 421 4.7.0 Our system has detected an unusual rate of unsolicited mail originating from your IP address. Mail sent from your IP address has been temporarily rate limited (Email / SMTP)421 4.7.0 Try again l…450 4.7.1 Greylisted, please try again later — SMTP: 450 4.7.1 <user@example.com>: Recipient address rejected: Greylisted, see http://postgrey.schweikert.ch/help/example.com.html (Email / SMTP)450 4.7.1 Greylisted,…451 4.3.0 Local error in processing — SMTP: 451 4.3.0 Error: queue file write error / 451 Requested action aborted: local error in processing (Email / SMTP)451 4.3.0 Local error…452 4.2.2 Mailbox full / over quota — SMTP: 452 4.2.2 The email account that you tried to reach is over quota (Email / SMTP)452 4.2.2 Mailbox ful…Command "x" is not defined — Laravel: Symfony\Component\Console\Exception\CommandNotFoundException: Command "make:livewire" is not defined. Did you mean one of these? (Laravel)Command "x" is not de…env() returns null (config cached) — Laravel: .env changes ignored / env('X') returns null after php artisan config:cache (Laravel)env() returns null (c…Laravel storage — Laravel: The stream or file "storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied (PHP)Laravel storageLaravel: …

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.