Search code examples
phpphpmailerstarttls

PHPMailer & STARTTLS not sending email


Message not sending with such settings

$mail = new PHPMailer;
$mail->SMTPDebug = 4;                               
$mail->isSMTP();                                      
$mail->Host = "domain.com";  
$mail->SMTPAuth = true;                               
$mail->Username = "login";                 
$mail->Password = "pasw";                         
$mail->SMTPSecure = "tls";                            
$mail->Port = 2525;                                    
$mail->CharSet = 'UTF-8';

openssl extension is loaded. Dеbug output is here https://justpaste.it/1ecjw First problem line there is 2017-12-08 09:48:53 SMTP -> get_lines(): $str is "502 5.5.1 command not supported in "STARTTLS""

telnet says that there is ESMTP service. I don't know what to investigate next...


Solution

  • Not too complicated - your mail server does not support STARTTLS. If it did it would appear in the list of capabilities after the first EHLO command, which is this:

    250-ENHANCEDSTATUSCODES
    250-PIPELINING
    250-CHUNKING
    250-8BITMIME
    250-AUTH CRAM-MD5 PLAIN LOGIN
    250-AUTH=CRAM-MD5 PLAIN LOGIN
    250-XACK
    250-SIZE 0
    250-VERP
    250 DSN
    

    STARTTLS is not in that list. It may still support encryption via SMTPSecure = 'ssl' and Port = 465, but otherwise you'll need to fall back to the most secure auth option over this unencrypted channel, which is AuthType = 'CRAM-MD5'.

    ESMTP just means that it supports "Extended SMTP" with EHLO (and all that that implies), not just basic SMTP HELO.

    BTW - SMTPDebug = 4 is too noisy for this level of problem, you need 3 at most. Also, you're using an old version of PHPMailer, upgrade.