Connection could not be established with host smtp.gmail.com Network is unreachable #101 error in Laravel email
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Solving the "Connection could not be established with host smtp.gmail.com Network is unreachable #101" Error in Laravel
As developers, we often encounter frustrating issues where code works perfectly on our local machines but fails spectacularly when deployed to a remote server. The error message you are seeingâ`Connection could not be established with host smtp.gmail.com [Network is unreachable #101]`âis a classic indicator that the problem lies not within your Laravel configuration itself, but in the network connectivity or security settings of the hosting environment.
This post will walk you through the diagnosis and definitive steps required to resolve this specific SMTP connection failure when deploying Laravel applications to a remote server.
## Understanding the Root Cause: Network vs. Application Error
When you can successfully send mail from `localhost` but fail on the server, it almost always points to an environmental constraint rather than a faulty `.env` file. While the application code (Laravel) correctly formats the request, the operating system or the server's firewall is preventing the outgoing connection from being established.
The specific error code `#101` often relates to ICMP errors, meaning the host machine cannot find a route to reach the destination server (`smtp.gmail.com`). This strongly suggests one of the following issues on your remote server:
1. **Outbound Firewall Restriction:** The server's security group or local firewall is blocking outgoing connections on the necessary ports (587 or 465).
2. **Proxy Configuration:** If the server requires a proxy to reach the external internet, and that proxy is misconfigured or unavailable, the connection will fail.
3. **DNS Resolution Failure:** The server cannot correctly resolve the IP address for `smtp.gmail.com`.
4. **Server-Side Network Limits:** In some shared hosting environments, outbound SMTP connections might be strictly limited or blocked by the host provider.
## Step-by-Step Troubleshooting Guide
Since you have already tested switching between port 587 (TLS) and 465 (SSL) without success, we need to focus squarely on the network layer. Follow these steps methodically:
### 1. Verify Basic Network Connectivity (The Ping Test)
First, confirm that your server can even see the destination host. Log into your server via SSH and attempt a simple ping test.
```bash
ping smtp.gmail.com
```
If the ping fails or times out, this confirms a fundamental routing issue on the server side, pointing directly to firewall or routing problems. If the ping succeeds, proceed to check port connectivity.
### 2. Test Port Connectivity (The Telnet/nc Test)
Next, test if the specific SMTP ports are open for outbound traffic. Use `telnet` or `nc` (netcat) to see if a connection can be established on the required ports:
```bash
# Test port 587 (TLS)
telnet smtp.gmail.com 587
# Test port 465 (SSL)
telnet smtp.gmail.com 465
```
If these tests immediately fail or hang, it is a definitive sign that an external firewall (either your server's internal one or the hosting providerâs network rules) is blocking the outgoing connection attempts.
### 3. Review Server Firewall and Proxy Settings
If connectivity tests fail, you must adjust the server configuration:
* **Firewall Rules:** If you have root access, examine `iptables` or security group settings (if using a cloud provider like AWS/GCP) to ensure that outbound traffic on ports 587 and 465 is explicitly allowed.
* **Proxy Environment Variables:** If your server requires an HTTP proxy to access the internet, you need to set the environment variables correctly for PHP/Laravel to use it:
```bash
export http_proxy="http://proxy.example.com:8080"
export https_proxy="http://proxy.example.com:8080"
```
You can also configure Laravel's environment to use these variables, which is a crucial step in optimizing application performance and connectivity when dealing with external services like those discussed on platforms such as [laravelcompany.com](https://laravelcompany.com).
## Conclusion
The "Network is unreachable #101" error during SMTP transmission is rarely an issue with the Laravel email setup itself; it is almost always a network infrastructure problem on the host machine. By systematically testing basic connectivity (ping, telnet) and checking server-side firewall rules and proxy settings, you can isolate whether the blockage is due to routing, security rules, or proxy configuration. Focus your debugging efforts on the operating system layer rather than just the application code to achieve a stable and reliable email delivery system.