SMTP Connection Errors

Problem

While attempting to send email, you see one of the following errors:

Could not connect to SMTP host

or

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

If you have enabled SMTP Debug for your mail provider in the Mail tab at Configuration () > System Settings > General Settings, the log entry will also include the following details:

    SMTP Debug: Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array()

    SMTP Debug: Connection failed. Error #2: stream_socket_client(): SSL  operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate  verify failed  [/path/to/whmcs/vendor/phpmailer/phpmailer/src/SMTP.php  line 375]

    SMTP Debug: Connection failed. Error #2:  stream_socket_client(): Failed to enable crypto  [/path/to/whmcs/vendor/phpmailer/phpmailer/src/SMTP.php  line 375]

    SMTP Debug: Connection failed. Error #2:  stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465  (Unknown error)  [/path/to/whmcs/vendor/phpmailer/phpmailer/src/SMTP.php  line 375]

    SMTP Debug: SMTP ERROR: Failed to connect to server:  (0)

    SMTP Debug: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

If you have enabled SMTP Restrictions in WHM at WHM » Home » Security Center » SMTP Restrictions and are using an external mail server, you may also see this error message at Configuration () > System Logs:

Connection failed. Error #2: stream_socket_enable_crypto(): Peer certificate CN=`example.com' did not match expected CN=`smtp.gmail.com' [/path/to/whmcs/vendor/phpmailer/phpmailer/src/SMTP.php line 426]

Cause

There are several possible reasons for this error:

Incorrect SMTP Settings

The SMTP settings in the Mail tab at Configuration () > System Settings > General Settings are incorrect.

Solution

Check with your system administrator to verify that you have entered the correct SMTP host, port, username, and password, and that you have selected the appropriate SSL type for use with your mail server.

For example, selecting TLS and the port number 256 would cause this error.

The most common port assignments for each SSL type are:

  • None25 or 26
  • SSL465 or 587
  • TLS587

External Mail Servers

The mail server is blocking connections from your WHMCS installation’s server or the server that hosts your WHMCS installation is blocking connections to the external SMTP server.

Solution

Adjust your mail server configuration to allow connections to external SMTP servers.

Certificate Validation Errors

The mail server is advertising that TLS connections are available, but when a secure connection is attempted it fails due to a certificate validation error.

Solution

Ensure that you have installed a validated certificate on the mail server.

Workaround

Set the SMTPAutoTLS setting to false in the /vendor/phpmailer/phpmailer/class.phpmailer.php file.

DNS Failure

The server cannot resolve the supplied SMTP host.

Solution

Work with your system administrator or hosting provider to resolve the issue.

Firewall Block

A rule in your firewall is preventing the server from connecting to the SMTP host.

Solution

Find the firewall rule that is causing the issue and disable it.

SSL Certificate Misconfiguration

An SSL certificate on the SMTP server is expired.

Solution

Make certain to install a valid SSL certificate on your SMTP server.

Last modified: October 29, 2024