SMTP error 111
Connection refused — an OS socket error, not an SMTP code.
Updated Jul 1, 2026
SMTP 111 is not an SMTP reply code. It is the POSIX socket error ECONNREFUSED ("connection refused"): the TCP connection to your mail server was rejected before the SMTP conversation could start. Fix the host and port, open outbound firewall rules on 25/465/587, and lift any host-level SMTP restrictions.
Correct the host and port, open outbound firewall rules on 25/465/587, and lift any host-level SMTP restrictions.
What it means
PHPMailer and Python's smtplib surface "111" straight from the operating system — it is not a server response. ECONNREFUSED happens at the network layer, before SMTP begins: your client never got to greet the server, log in, or name a recipient. That rules out a whole class of "explanations" — a bad recipient address, a wrong SMTP password, or the recipient blocking something cannot be the cause, because you never reached the point in the dialogue where any of those would matter.
Common causes
Pointing at a host with no SMTP listener, or a port the server is not on. Use 587 (STARTTLS) or 465 (implicit TLS) for submission; port 25 is server-to-server and widely blocked for clients.
Many hosts and ISPs block outbound 25/465/587 by default to curb spam. Very common on shared and VPS hosting.
cPanel/WHM's "SMTP Restrictions" forces port-25 traffic through the local mail server; a rule like CSF's SMTP_BLOCK can restrict 465/587. Check both.
Pointing at localhost when no local mail server is running.
The hostname resolves to a filtered IPv6 address while IPv4 would work.
How to fix it
- Confirm host/port and test connectivity
From the sending server, test the TCP path. A "connection refused" here is a network/port problem, not your mail code.
openssl s_client -connect smtp.example.com:465 openssl s_client -starttls smtp -connect smtp.example.com:587 nc -vz smtp.example.com 587 - Open outbound firewall rules
Allow egress on your submission port (usually 587 or 465). On your own server, permit outbound; on shared hosting, ask the host to confirm outbound SMTP is not blocked.
- Lift host SMTP restrictions
On cPanel/WHM disable "SMTP Restrictions" (or the CSF SMTP_BLOCK rule), or add your sending user to the allow list.
- Match the port to the encryption mode
Use 465 with implicit TLS or 587 with STARTTLS. Do not request STARTTLS on 465.
- Force IPv4 if IPv6 is filtered
Resolve and connect to the IPv4 address to bypass a blocked AAAA record.
Common questions
Is 111 an actual SMTP status code?
No. SMTP replies are three-digit codes in RFC 5321. 111 is the OS errno ECONNREFUSED — a TCP error meaning the connection was refused before SMTP started.
PHPMailer says 111 but my credentials are right — why?
Credentials do not matter yet. 111 means the connection was refused before login; you never reached authentication. Look at host, port, and firewall.
Which port should I use?
587 with STARTTLS or 465 with implicit TLS. Avoid port 25 for client submission — it is widely blocked.