PHPMailer - infinityfree - STARTTLS

something is strange with this function stream_socket_enable_crypto it always fails when running in PHP environment at infinity.

this function is essential to use TLS in SMTP

    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_TLS_CLIENT
        )) {
            return false;
        }
        return true;
    }

Google STMP? Or specific ports? Only general ports are allowed.

I am using Yandex. For some reason on another hoster the exact same code works. I enabled the debug and it fails always at the same function when opening the socket encrypted.

I m using port 587 or 465.

    $mail = new PHPMailer(); 
    
    $mail->Debugoutput= "phpmailer_debug_callback";

    $mail->IsSMTP();
    $mail->IsHTML(true);
    $mail->Host       = $mailhost;
    $mail->SMTPDebug  = 4; 
    $mail->SMTPAuth   = true;
    //$mail->Port       = 587;
    $mail->Port       = 465;
    $mail->SMTPSecure = 'ssl';
    $mail->Username   = $mailusername;
    $mail->Password   = $mailpassword;

SSL on port 465 fails

TLS on port 587 fails

yandex does not support un-encrypted at port 25

so no options left.

Maybe also try to add this code over the one you wrote above and see if it works:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
1 Like

Sure, I give it a shot – thanks.

NOPE. does not change. still no crypt socket.

this is the code

    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_TLS_CLIENT
        )) {
            echo ">> failed to start [stream_socket_enable_crypto]";
            return false;
        }
        echo ">> success to start [stream_socket_enable_crypto]";
        return true;
    }

and this is the logfile:

debug level 4; message: CLIENT -> SERVER: STARTTLS
;debug level 4; message: SMTP -> get_lines(): $data was "";debug level 4; message: SMTP -> get_lines(): $str is "220 Go ahead
";debug level 4; message: SMTP -> get_lines(): $data is "220 Go ahead
";debug level 4; message: SERVER -> CLIENT: 220 Go ahead

**>> failed to start [stream_socket_enable_crypto]**

debug level 4; message: CLIENT -> SERVER: QUIT
;debug level 4; message: SMTP -> get_lines(): $data was "";debug level 4; message: SMTP -> get_lines(): $str is "MIA`N�n��CH^�o[ޓ{2i�N���anh�??�0/2���g��,�c�<����/��ch�348>9x���n�^��{�������W�;L���a�0vߡI�9�R��gJ�^�L��wI���a�
";debug level 4; message: SMTP -> get_lines(): $data is "MIA`N�n��CH^�o[ޓ{2i�N���anh�??�0/2���g��,�c�<����/��ch�348>9x���n�^��{�������W�;L���a�0vߡI�9�R��gJ�^�L��wI���a�
";debug level 4; message: SMTP -> get_lines(): $data was "MIA`N�n��CH^�o[ޓ{2i�N���anh�??�0/2���g��,�c�<����/��ch�348>9x���n�^��{�������W�;L���a�0vߡI�9�R��gJ�^�L��wI���a�
";debug level 4; message: SMTP -> get_lines(): $str is ">Ad�\dڡF��{p=2��%����C�lؿ��D�锸�(s�����{75���$�Ϋ&����P�j��[��RYp'�N�ɛ=��յ�����w-��
:Ԛ�k���m>��{b�:�(Mvj4LD��16~4�t-uLF��z�"�1z�"s��zX0�׊���2vq��+��.D&�L&C8ؿ�A";debug level 4; message: SMTP -> get_lines(): $data is "MIA`N�n��CH^�o[ޓ{2i�N���anh�??�0/2���g��,�c�<����/��ch�348>9x���n�^��{�������W�;L���a�0vߡI�9�R��gJ�^�L��wI���a�
>Ad�\dڡF��{p=2��%����C�lؿ��D�锸�(s�����{75���$�Ϋ&����P�j��[��RYp'�N�ɛ=��յ�����w-��
:Ԛ�k���m>��{b�:�(Mvj4LD��16~4�t-uLF��z�"�1z�"s��zX0�׊���2vq��+��.D&�L&C8ؿ�A";debug level 4; message: SERVER -> CLIENT: MIA`N�n��CH^�o[ޓ{2i�N���anh�??�0/2���g��,�c�<����/��ch�348>9x���n�^��{�������W�;L���a�0vߡI�9�R��gJ�^�L��wI���a�
>Ad�\dڡF��{p=2��%����C�lؿ��D�锸�(s�����{75���$�Ϋ&����P�j��[��RYp'�N�ɛ=��յ�����w-��
:Ԛ�k���m>��{b�:�(Mvj4LD��16~4�t-uLF��z�"�1z�"s��zX0�׊���2vq��+��.D&�L&C8ؿ�A;debug level 4; message: SMTP ERROR: QUIT command failed: MIA`N�n��CH^�o[ޓ{2i�N���anh�??�0/2���g��,�c�<����/��ch�348>9x���n�^��{�������W�;L���a�0vߡI�9�R��gJ�^�L��wI���a�
>Ad�\dڡF��{p=2��%����C�lؿ��D�锸�(s�����{75���$�Ϋ&����P�j��[��RYp'�N�ɛ=��յ�����w-��
:Ԛ�k���m>��{b�:�(Mvj4LD��16~4�t-uLF��z�"�1z�"s��zX0�׊���2vq��+��.D&�L&C8ؿ�A;debug level 4; message: Connection: closed;debug level 4; message: SMTP connect() failed.;sendViaSMTP() - failed

for some reason the str return are becomming weird after QUIT

It looks like something is wrong with checking the certificates at infinityFree.

Believe it or not, but it is 100% certificate related by infinity.

  1. when disabling the certificate check all goes well
  2. Problem is, that I did use an old PHPMailer, which was not supporting $mail->SMTPOptions
  3. I fixed that
  4. voila it works

@Ergastolator1 – thanks!!

Solution is to DISABLE certificate check!
Which is not good at all.

$mail->SMTPOptions = array(
   'ssl' => array(
       'verify_peer' => false,
       'verify_peer_name' => false,
       'allow_self_signed' => true
   )
);
2 Likes

Final configuration:

$mail = new PHPMailer(); 

$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Debugoutput= "phpmailer_debug_callback";
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);
$mail->Host       = $mailhost;
$mail->SMTPDebug  = 4; 
$mail->SMTPAuth   = true;
$mail->AuthType   = 'LOGIN';
$mail->Port       = 587;
$mail->SMTPSecure = 'tls';
$mail->Username   = $mailusername;
$mail->Password   = $mailpassword;

Do you still get this problem with an updated PHPmailer and the SSL checks enabled? Because unless Yandex has very weird/broken SSL configuration, you should just be able to use verified SSL. I fully agree with you, disabling SSL verification should never be disabled in production.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.