Peer certificate CN did not match expected!

I was configuring the WP Mail SMTP plugin for WordPress on a client’s site. The default PHP mail function works well, but a couple of users reported mail getting delivered to the spam folder. So we decided to route mailing through one of the official IDs using SMTP.

We installed the plugin and configured the credentials. The task was supposed to be about 10 minutes of work, but the test mail failed. We had an SMTP connect() failed error in the debug log. We found out it was a misconfiguration at the server level based on the following quotes found on forums:

“Note that the default value of SSLProxyCheckPeerCN is off in httpd 2.2.x and on in httpd 2.4.x. Note that SSLProxyCheckPeerExpire and SSLProxyCheckPeerName also now default to on in 2.4.”

And

check SSL module mod_ssl.so is loaded in httpd.conf

Everything was just fine in httpd.conf, which is auto-generated in cPanel/WHM. On searching the cPanel support forum, we found there’s a hardening setting in WHM > SMTP Restriction. So if you are stuck with this issue, make sure to disable it. SMTP will then work like a charm.