How to force TLS 1.2 usage for PhpMailer 5.2

Viewed 9535

Recently the 3rd party email service provider I was using made a change. They disabled support for TLS 1.0 and TLS 1.1.

I provide support for an ancient system that still uses php 5.3 and phpmailer 5.2.

My tests indicates that TLS 1.2 is enabled.

But, the PHPMailer code cannot connect to the email server after the disabling of TLS 1.0 and 1.1

Also, note that I am not a full time php expert.

Is there a way to make PHPMailer 5.2 use tls 1.2?

2 Answers

Look for constant STREAM_CRYPTO_METHOD_TLS_CLIENT in file class.smtp.php and update that to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT Like this:

public function startTLS()
{
    if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
        return false;
    }
    // Begin encrypted connection
    if (!stream_socket_enable_crypto(
        $this->smtp_conn,
        true,
        STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
    )) {
        return false;
    }
    return true;
}

You should run phpinfo() in a small php script on your server to make sure TLS 1.2 is available in the first place.

It's not up to PHPMailer, its up to the version of PHP that you're using to run it, so the solution is to update your PHP version. The major changes relating to TLS were largely in PHP 5.6, so upgrading to that would be a good intermediate point if you're really stuck with this legacy version.

Related