Wordpress: Unable to send emails via SMTP

Created:

2017-05-18 21:01:09 UTC

Modified:

2017-08-17 21:49:00 UTC

3

Was this article helpful?


Have more questions?

Submit a request

Wordpress: Unable to send emails via SMTP

Applicable to:

  • Plesk for Linux

Symptoms

Wordpress is configured to send emails via SMTP at Wordpress Dashboard > Settings > Email:

From Email user@example.com
From Name User Name
Mailer            Send all WordPress emails via SMTP.
SMTP Host example.com
SMTP Port 25
Encryption No encryption.
Authentication Yes: Use SMTP authentication.
Username user@example.com
Password *********

Send a Test Email fails with the error below:

2017-05-18 20:09:55 CLIENT -> SERVER: STARTTLS
2017-05-18 20:09:55 SMTP -> get_lines(): $data is ""
2017-05-18 20:09:55 SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"
2017-05-18 20:09:55 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-05-18 20:09:55 SMTP Error: Could not connect to SMTP host.

The following error can be found in /var/log/maillog:

May 05 20:09:55 n01 postfix/smtpd[505884]: lost connection after STARTTLS from unknown[203.0.113.2]
May 05 20:09:55 n01 postfix/smtpd[505884]: disconnect from unknown[203.0.113.2]
May 05 20:09:55 n01 postfix/smtpd[505884]: connect from unknown[203.0.113.2]
May 05 20:09:55 n01 postfix/smtpd[505884]: SSL_accept error from unknown[203.0.113.2]: 0

Self-signed SSL certificate is used for mail (Plesk > Tools & Settings > SSL/TLS Certificates).

Cause

By default, wp-mail-smtp module always tries to use TLS connection if it realizes that the server supports STARTTLS (according to EHLO). Even if No encryption option is selected.

Since a self-signed certificate is used on the server, the certificate verification by PHP gets failed.

Resolution

Install a trusted SSL certificate for mail.

As a workaround, create a backup of class-phpmailer.php file and set public $SMTPAutoTLS to false:

# cp -p /var/www/vhosts/example.com/httpdocs/wp-includes/class-phpmailer.php{,.orig} 
# diff /var/www/vhosts/example.com/httpdocs/wp-includes/class-phpmailer.php{,.orig}
260c260
<    public $SMTPAutoTLS = false;
---
>    public $SMTPAutoTLS = true;

wp-mail-smtp module would work as expected for No encryption method.

Have more questions? Submit a request
Please sign in to leave a comment.