Search code examples
emailphpmailer

PHPMailer Update Issue (from 5.2.9 to 5.2.16)


PHPMailer works great, I've been using it for ages and it's pretty good. I have had version 5.2.9 on my server and have got the newer, 5.2.16 uploaded,

Now my sites have issues of:

"SMTP Error: SMTP connect() failed."

I have added $mail->SMTPDebug = 4; and it gives me this:

2016-11-15 17:18:10 Connection: opening to localhost:25, timeout=300, options=array (
                                      )
2016-11-15 17:18:10 Connection: opened
...
removed excess repetative lines
...

2016-11-15 17:18:10 SERVER -> CLIENT: 250-mail.servernetwork.co.uk Hello www.domain.co.uk [::1]
                                      250-SIZE 52428800
                                      250-8BITMIME
                                      250-PIPELINING
                                      250-AUTH PLAIN LOGIN
                                      250-STARTTLS
                                      250 HELP
2016-11-15 17:18:10 CLIENT -> SERVER: STARTTLS
2016-11-15 17:18:10 SMTP -> get_lines(): $data is ""
2016-11-15 17:18:10 SMTP -> get_lines(): $str is  "220 TLS go ahead
                                      "
2016-11-15 17:18:10 SERVER -> CLIENT: 220 TLS go ahead
2016-11-15 17:18:10 SMTP Error: Could not connect to SMTP host.
2016-11-15 17:18:10 CLIENT -> SERVER: QUIT
2016-11-15 17:18:10 SMTP -> get_lines(): $data is ""

Nothing else has changed on the server. Reverting to PHPMailer Version 5.2.9 removes this error (and emails are sent ok).

I have also tried to update from 5.2.9 to 5.2.14 and 5.2.13 and the same error occurs. I have made no changes to the DNS and there are no DKIM or other identifiers set in the PHPmailer classes to allow version 5.2.9 but not 5.2.13 or 5.2.16 ones.

I'm using PHP Version 5.6.2.

Any clues as to why this is so?

The sending code: (I realise the code is not the best but it's an older site I picked at random to test out PHPMailer 5.2.16)

$mail           = new PHPMailer();
//$mail->SMTPDebug=4;
$mail->Host     = "localhost";
$mail->WordWrap = 78;
$mail->isSMTP();
$mail->From     = $fromMail;
$mail->FromName = "Website: ".$name;
$mail->AddAddress($toEmail);
$mail->Subject = $member['bizname'] . " Enquiry";
$mail->Body    = $message;
if (!$mail->Send()) {  
  ...
 }

Solution

  • After spending a day or so asking various related questions, I found the answer lies with an update applied in PHPMailer 5.2.10.

    I found that while my server is TLS certified, there seems to be a problem with using a localhost Host; possibly that PHPMailer may be trying to check the certificate applies to localhost domain, which of course it doesn't.

    I found a solution to sending mail via Localhost now is therefore to disable auto-TLS with the following:

        $mail->SMTPAutoTLS = false; 
    

    Using this all emails now send correctly.


    NOTE

    As Bodi0 stated using SMTPAuth is best practise, however I didn't realise that it is unnessecary for localhost mail servers as the authenticaton is implicit.

    Comments on this answer to a related question about ->SMTPSecure settings gives more details.