Apache / PHP server SMTP mail with SSL or TLS

185 Views Asked by At

I create a simple PHP -> SMTP mail send function. It never need a library.
I can send SSL type mails like a charm but i have problem for TLS.

Question : Where i do a wrong step with this function for TLS security ?

important notes :

  • it can send SSL level mail like 'ssl://smtp.zoho.eu:465'.
  • SSL mails (ssl://smtp.zoho.eu:465) never go spam box -> complete secure and success.
  • Complete socket/host type function with PHP. -> never use any library like PHPMailer or sendmail().
  • My TLS version is already TLS 1.3. -> i control they are with info and some openssl tests.
  • For ZOHO smtp need SSL : 465 TLS :587 ports.
  • All ports controlled from me. -> they are ready for send mails.
  • Sended SSL mails look like have TLS. -> really interesting.

SSL TYPE ------------------------- : For example : ( This works like a charm. )

// SMTP connection
    $socket = stream_socket_client('ssl://smtp.zoho.eu' . ':' . '465', $errno, $errstr, '10', STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);

    if (!$socket) {
        throw new Exception("Unable to connect to SMTP server: $errstr ($errno)");
    }

    stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

    // Server Connection
    process_command($socket, "EHLO " . gethostname());

    // Auth
    process_command($socket, "AUTH LOGIN");
    process_command($socket, base64_encode($auth_username));
    process_command($socket, base64_encode($auth_password));

    ...
    ...

TLS TYPE ------------------------- : For example : ( Errors about... )

// SMTP connection
    $socket = stream_socket_client('smtp.zoho.eu' . ':' . '587', $errno, $errstr, '10', STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);

    if (!$socket) {
        throw new Exception("Unable to connect to SMTP server: $errstr ($errno)");
    }

    // Server Connection
    process_command($socket, "EHLO " . gethostname());

    process_command($socket, "STARTTLS");

    stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

    process_command($socket, "EHLO " . gethostname());

    // Auth
    process_command($socket, "AUTH LOGIN");
    process_command($socket, base64_encode($auth_username));
    process_command($socket, base64_encode($auth_password));

    ...
    ...

You can look log details for 2 SSL/TLS images.
SSL : SSL mail logs.

TLS : TLS mail logs.

Problem : TLS type mails give error with 587.

0

There are 0 best solutions below