Symptoms
When submitting a form on a website that uses PHPMailer or sending a test email via WP Mail SMTP, the operation fails with:
Warning: stream_socket_enable_crypto(): Peer certificate CN=`server.hostname.com' did not match expected CN=`localhost' in C:Inetpubvhostsexample.comhttpdocswp-includesclass-smtp.php on line 369
...
SMTP ERROR: Failed to connect to server: (0)SMTP connect() failed
Cause
Incorrect SMTP Host is specified in configuration.
Resolution
Use the domain name or the server hostname in mail configuration.
Note: Domain / hostname must be secured with an SSL certificate.
Note: Hostname can be found on the Home page in Plesk or in MailEnable Management Console > Services > localhost > Services and Connectors > SMTP Properties > General > Local domain name.
Examples:
PHPMailer
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'example.com'; // Specify main and backup server
$mail->Port = 25; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'tls';
WP Mail SMTP plugin for WordPress (WordPress Admin > Settings > Email > SMTP Host):