PHPMailer generates PHP Warning: stream_socket_enable_crypto(): Peer certificate did not match expected

I had the same problem and I found the answer in the PHPMailer documentation. PHP 5.6 certificate verification failure In a change from earlier versions, PHP 5.6 verifies certificates on SSL connections. If the SSL config of the server you are connecting to is not correct, you will get an error like this: Warning: stream_socket_enable_crypto(): … Read more

PHPMailer: SMTP Error: Could not connect to SMTP host

Since this questions shows up high in google, I’d like to share here my solution for the case where PHP was just upgraded to version 5.6 (which has stricter SSL behavior). The PHPMailer wiki has a section on this: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure The suggested workaround is including the following piece of code: $mail->SMTPOptions = array( ‘ssl’ => … Read more

Error handling with PHPMailer

PHPMailer uses Exceptions. Try to adopt the following code: require_once ‘../class.phpmailer.php’; $mail = new PHPMailer(true); //defaults to using php “mail()”; the true param means it will throw exceptions on errors, which we need to catch try { $mail->AddReplyTo(‘name@yourdomain.com’, ‘First Last’); $mail->AddAddress(‘whoto@otherdomain.com’, ‘John Doe’); $mail->SetFrom(‘name@yourdomain.com’, ‘First Last’); $mail->AddReplyTo(‘name@yourdomain.com’, ‘First Last’); $mail->Subject=”PHPMailer Test Subject via mail(), advanced”; … Read more