PHPMailer: SMTP Error: Could not connect to SMTP host PHPMailer: SMTP Error: Could not connect to SMTP host php php

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' => array(        'verify_peer' => false,        'verify_peer_name' => false,        'allow_self_signed' => true    ));

This should work for PHPMailer 5.2.10 (and up).

Note: Obviously, and also as suggested in that wiki, this should be a temporary solution!

The correct fix for this is to replace the invalid, misconfigured or self-signed certificate with a good one.


In my case it was a lack of SSL support in PHP which gave this error.

So I enabled extension=php_openssl.dll

$mail->SMTPDebug = 1; also hinted towards this solution.

Update 2017

$mail->SMTPDebug = 2;, see: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling-debug-output


Your problem is most likely this

Connection Security: STARTTLSConnection Security: SSL/TLS

Those are 2 different protocols, are you using the correct one, whatever one you're using in Thunderbird needs to be used.

Try setting the variable:

// if you're using SSL$mail->SMTPSecure = 'ssl';// OR use TLS$mail->SMTPSecure = 'tls';