PHPMailer: SMTP Error: Could not connect to SMTP host. Failed to connect to server (SMTP connect() failed)
PHPMailer could not open a socket to the SMTP server — wrong host/port/encryption, a blocked port, or a PHP/OpenSSL restriction.
SMTP Error: Could not connect to SMTP hostSMTP connect() failedFailed to connect to server PHPMailerSMTP ERROR: Failed to connect to server: Connection timed out (110)PHPMailer SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Meaning
Enable SMTPDebug = SMTP::DEBUG_SERVER for the full dialogue. Typical fixes: match SMTPSecure with the port (ENCRYPTION_STARTTLS for 587, ENCRYPTION_SMTPS for 465), open the outbound port, enable openssl in PHP, and make sure allow_url_fopen/sockets are not disabled by the host.
Common causes
- Wrong
Host,PortorSMTPSecurevalue - Hosting provider blocks outbound SMTP
- PHP
opensslextension missing - Firewall/SELinux blocking
httpd_can_sendmail/network connect - SMTP host requires a different TLS version
⚡ Quick fix
- Set
$mail->SMTPDebug = 2;to see where it stops - Use 587 + STARTTLS or 465 + SMTPS consistently
- Ask the host to open the port or use their relay
Detailed fix by platform
Linux
php -m | grep -i openssland, on SELinux systems,sudo setsebool -P httpd_can_network_connect 1
Code examples
Matching port and mode
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // 587
$mail->Port = 587;
$mail->SMTPDebug = SMTP::DEBUG_SERVER;How to diagnose
- Debug — Where does the dialogue stop?
- Pair — SMTPSecure matches port?
- Host — Outbound allowed and openssl loaded?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 421 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
- 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
- 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
Most viewed in Email / SMTP
Other ways to find it
Where this error sits
Origin: Network. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 4 Nov 2026