'How to force TLS 1.2 usage for PhpMailer 5.2

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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Constantine