PHPMailer: SMTP connect() failed Email / SMTP Origin: Network Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: SMTP PHP

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, Port or SMTPSecure value
  • Hosting provider blocks outbound SMTP
  • PHP openssl extension missing
  • Firewall/SELinux blocking httpd_can_sendmail/network connect
  • SMTP host requires a different TLS version

⚡ Quick fix

  1. Set $mail->SMTPDebug = 2; to see where it stops
  2. Use 587 + STARTTLS or 465 + SMTPS consistently
  3. Ask the host to open the port or use their relay

Detailed fix by platform

Linux

  1. php -m | grep -i openssl and, on SELinux systems, sudo setsebool -P httpd_can_network_connect 1

Code examples

Matching port and mode

php
$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

  1. Debug — Where does the dialogue stop?
  2. Pair — SMTPSecure matches port?
  3. 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:

Where this error sits

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

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 (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…Outbound port 25 blocked — SMTP: telnet smtp.example.com 25 — Connection timed out (cloud provider blocks port 25) (Email / SMTP)Outbound port 25 bloc…sendmail: not found (PHP mail) — PHP: sh: 1: /usr/sbin/sendmail: not found — mail() returns false (Email / SMTP)sendmail: not found (…SMTP Error: Could not authenticate — WordPress / PHPMailer: SMTP Error: Could not authenticate / SMTP connect() failed (WordPress)SMTP Error: Could not…SSL: WRONG_VERSION_NUMBER (SMTP port) — SMTP: [SSL: WRONG_VERSION_NUMBER] wrong version number — SMTP over SSL on a STARTTLS port (Email / SMTP)SSL: WRONG_VERSION_NU…WordPress: Could not instantiate mail function — WordPress: Mailer Error: Could not instantiate mail function. / wp_mail() failed (Email / SMTP)WordPress: Could not …PHPMailer…

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.