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

**Code:** `Laravel: Connection could not be established with host` · **Category:** Email / SMTP · **Seen on:** SMTP, Laravel, PHP

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/email/laravel-connection-could-not-be-established)
