Could not connect to SMTP host (SMTP connect() failed) in WordPress

Your site tried to hand an email to its mail server and never got as far as saying hello. That is what “Could not connect to SMTP host” tells you when WordPress records it. No password was checked and no message was sent, so the problem sits between your WordPress server and the mail server: the address, the port, the encryption setting, or something on the network that stopped the connection.

The awkward part is that the error text does not change with the cause. In our tests, five different faults left WordPress with exactly the same line. The useful detail is one level down, in the mailer’s debug transcript, and when you cannot get a transcript, the time the test took to fail can provide a rough clue.

The error as WordPress records it

When wp_mail() fails, WordPress passes the mailer’s error message to the wp_mail_failed action, and that message is what an email log or a monitoring plugin shows you. In our tests it took one of three forms:

SMTP Error: Could not connect to SMTP host. Failed to connect to server
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:0A000086:SSL routines::certificate verify failed

The first is the common one: a refused port, a blocked port, a wrong host name and two encryption problems all produced it word for word. The second, with nothing after the full stop, appeared when the connection opened but the server never answered. The third is the only form that names its own cause.

Where “SMTP connect() failed” comes from

SMTP connect() failed. is PHPMailer’s message for the same failure; PHPMailer is the library WordPress bundles to send mail. PHPMailer raises it only when it runs with exceptions switched off. wp_mail() switches them on, so the bundled PHPMailer throws “Could not connect to SMTP host” first, and none of our test runs recorded “SMTP connect() failed”. If your log shows SMTP connect() failed., whatever wrote that log entry may be passing on PHPMailer’s ErrorInfo rather than WordPress’s exception message. The string does not say which plugin or mailer that is, so check the log of the one that recorded it. The connection stage that failed is the same, and so is everything below.

What failed, and at which stage

An SMTP send happens in stages. The site opens a network connection to the mail server, the server sends a greeting, the two agree on encryption, the site logs in, and only then does the message go across. “Could not connect” means the first stages never completed: the connection, the greeting, or the encryption handshake.

Your SMTP username and password were never tried, so changing them will not help; a rejected password produces a different error, “Could not authenticate”. And the mail server holds no record of a message, because none reached it. For errors from the later stages, the WordPress email troubleshooting guide sorts each message by the stage it comes from.

What public reports show

We read 8 public reports of this error: 7 WordPress.org support threads from 2023 to November 2026, and one older Stack Overflow thread about PHPMailer outside WordPress. Seven of the eight were timeouts; one was a refused connection. Only the Stack Overflow thread confirmed a cause: a firewall rule on the sending server that blocked outbound mail, and removing the rule fixed it. None of the WordPress.org threads ended with a confirmed answer.

That sample is too small to rank causes, and we do not. It does say what people run into: the slow, silent timeout is reported far more often than the instant refusal, which fits a blocked outbound port better than a typo in the settings. Treat that as a lead, not a finding.

How to tell which cause you have

The cause is in the debug transcript, the line-by-line record of what the mailer and the server said to each other (the guide to reading an SMTP session log walks through one in full). If your SMTP plugin has a debug log, enable it for one test and look for the SMTP transcript. Plugins name that setting differently and record different amounts of detail; check the plugin’s current documentation. Without a plugin, a short snippet does the same. Add it as a must-use plugin (a PHP file in wp-content/mu-plugins/), send one test, read your PHP error log, and remove the file:

<?php
add_action( 'phpmailer_init', function ( $phpmailer ) {
    $phpmailer->SMTPDebug   = 3;           // connection-level detail
    $phpmailer->Debugoutput = 'error_log'; // write to the PHP error log
}, 99 );

PHPMailer hides the login credentials in the transcript, but it still names your mail server and the addresses, so do not paste it publicly unedited. An SMTP plugin that sets its own debug level may override this; its own log is the better source then.

Match the transcript against this table. Each line comes from a test run we made, and the last column is how long that run took to fail.

Line in the transcript Cause Error WordPress recorded Time to fail
Unable to connect to ... (Connection refused) and Connection refused (111) A service or firewall actively rejected the connection: nothing listens on that port at that address, or a firewall rejects it ... Failed to connect to server under 1 second
Unable to connect to ... (Connection timed out) and Connection timed out (110) No response before the connect gave up: traffic dropped by a firewall or on the network path, or an unreachable address ... Failed to connect to server about 2 minutes (135 s in our test)
getaddrinfo for <host> failed: Name or service not known The host name did not resolve from your server: a typo, a retired host name, or a DNS problem ... Failed to connect to server under 1 second
opening to ssl://..., then wrong version number Encryption set to ssl on a port that expects STARTTLS, such as 587 ... Failed to connect to server under 1 second
Connection: opened, then an empty SERVER -> CLIENT: line 5 minutes later Encryption set to tls (STARTTLS) on a port that expects encryption from the first byte, such as 465; or a server that accepts connections and never answers SMTP Error: Could not connect to SMTP host. 5 minutes (300 s)
certificate verify failed The server’s certificate is not one your server trusts the certificate form under STARTTLS; ... Failed to connect to server under SSL under 1 second

No transcript? Check how long it took. Without a transcript, time is only a clue. In this lab, refusal, failed name lookup, ssl against a STARTTLS port, and certificate failure took under a second; tls against a TLS-from-first-byte port took 300 seconds. A dropped TCP connection took 135 seconds, and an accepted but silent server took the full 300-second PHPMailer timeout. Other hosts and plugins can behave differently, so elapsed time does not identify the cause by itself. The 135-second figure is set by the server’s operating system, so another host may give up sooner or later; the five minutes is PHPMailer’s default Timeout of 300 seconds, which a plugin may change.

Two cases need care. The certificate failure only names itself under STARTTLS; on a port 465 connection it records the same message as a refused port, and only the transcript shows certificate verify failed. And setting tls on port 465 cannot be told apart from a silent server by the recorded error: the site waits for the server’s greeting while the server waits for the site to start encryption, until the timeout ends it.

The fix for each cause

Connection timed out: check the network path and host policy

A timeout means the connection attempt got no response before it gave up. A firewall or host policy can cause this, but a timeout does not identify where the traffic stopped. Check your host’s published policy, then ask whether connections from your server to the documented SMTP host and port are allowed. If the host will not allow the SMTP connection, your provider’s API mailer is the alternative to consider, but first confirm that your host lets your server reach that API over HTTPS.

If you run the server yourself, look at its own firewall too; the one confirmed cause in the reports we read was a rule on the sending server. On a cPanel server using ConfigServer Security & Firewall, check whether SMTP_BLOCK is enabled. cPanel documents this setting as blocking outbound SMTP connections except for the server’s mail processes.

If you have SSH access, test the port from the server itself. For port 587:

openssl s_client -connect smtp.example.com:587 -starttls smtp

For port 465, drop -starttls smtp, because the encryption starts at once:

openssl s_client -connect smtp.example.com:465

Replace the host name with your provider’s, then read the result:

  • A certificate printout and a 220 greeting mean the port is open from this server.
  • Connection refused is the refusal case in the next section.
  • A command that hangs is inconclusive: traffic may be dropped, or a service may have accepted the connection but not completed its greeting or TLS handshake. To narrow it down, read the mailer’s transcript, or run the test against the host and port your provider documents, using the encryption mode it expects there.

If the connection still times out against the host and port your provider documents, that points to a reachability problem, but the timeout does not say whether it sits with your server, the network path or the destination.

Connection refused: the wrong port, or nothing there

Use the port your mail provider documents for SMTP submission, and check the host name on the same page. A refusal means a service or a firewall actively rejected the connection; from the refusal you cannot tell which. In our test, pointing the same settings at a port with a server listening fixed it.

The host name does not resolve

The server could not turn the host name into an address. A typo or retired host name can cause this; so can a DNS or resolver problem. Confirm the exact host name in the provider’s current documentation and check whether it resolves from your server.

The encryption setting does not match the port

This is the case where the settings look right and are not. STARTTLS means the connection starts unencrypted and then switches encryption on with a command. For the common submission modes described in RFC 8314, port 587 uses STARTTLS and port 465 starts TLS immediately. Follow your provider’s documented host, port and encryption mode. In PHPMailer, the tls setting selects STARTTLS and ssl selects TLS from the start; other plugins may use different labels.

Port Encryption setting
587 STARTTLS (tls in PHPMailer)
465 TLS from the first byte (ssl in PHPMailer)

In our tests, changing only the encryption setting fixed both mismatches: tls on the STARTTLS port and ssl on the 465-style port each sent successfully.

The certificate is not trusted

certificate verify failed means the encryption handshake started and your server refused the mail server’s certificate. We reproduced it with a self-signed certificate, and the change that fixed it was a certificate the site trusts. An expired certificate or missing issuer CA can also fail certificate verification, but we did not test those cases and their exact transcript text may differ. On your side:

  • Use the exact host name your provider documents. The client checks that the host name you used matches a name on the certificate; an IP address or alias can fail that check if it is not listed.
  • If you use your host’s mail server, or you are on shared hosting, ask the provider to check the certificate and the CA bundle (the server’s list of trusted authorities) used by the server.

Some plugins offer a setting that turns certificate checks off. We did not test it, and we do not recommend it outside a private test setup: it removes the check that stops another machine from posing as your mail server and collecting your SMTP password. PHP verifies the certificate and its host name by default (SSL context options).

Check that it stays fixed

After the change, send a test and confirm two things: the test reports success, and the message arrives in the mailbox. The delivery check guide covers the second part.

A connection error can come back without any change on your site: a host tightens its firewall, a provider retires a host name, a certificate expires. A scheduled test can surface a later connection failure before you next need to send an email. nanoPost makes Email Check, a free plugin that sends a test on a schedule, keeps the result and the error text, and links each error to a page like this one. If you would rather not add a plugin, the wp_mail_failed hook guide shows how to log failures that reach the wp_mail_failed hook with a few lines of code.

How we tested

On 19 November 2026 we reproduced each cause on WordPress 7.1.5 with its bundled PHPMailer 7.1.1, on PHP 8.3.6 with OpenSSL 3.0.13. WordPress sent through a test SMTP server we control, configured through the phpmailer_init hook, and Email Check recorded the error that wp_mail_failed received. We made the server refuse the connection, drop it, stay silent, offer the wrong kind of encryption and present a self-signed certificate; we also used an unresolvable host name and an address that drops traffic. Other port numbers with the same encryption behaviour stood in for 465 and 587.

The limits: one PHP version, core WordPress with no SMTP plugin in the path (a plugin may reword the error), no live provider, and the 135-second timeout figure belongs to our server’s operating system. The public reports come from searches of WordPress.org support and Stack Overflow made the same day.

For the server’s reply codes once a connection does succeed, the SMTP field manual is the reference.

Could not connect to SMTP host (SMTP connect() failed) in WordPress details
Short Definition
WordPress's error when its mailer could not open a working connection to the SMTP server. Causes include a blocked or closed port, a host name that does not resolve, an encryption setting that does not match the port, and an untrusted certificate. No login or message was attempted.
Related Terms
smtp-field-manual