Search code examples
phpphpmailer

Error, connection dropped


For some reason all of a sudden one of the webforms we use to send emails has stopped working. The following error appears:

2016-10-17 07:42:15 Connection: opening to smtp.example.org.uk:25, timeout=300, options=array ( )
2016-10-17 07:42:15 Connection: opened 
2016-10-17 07:42:15 SERVER -> CLIENT: 220 smtp-ca.example.org.uk ESMTP
2016-10-17 07:42:15 CLIENT -> SERVER: EHLO forms.example.org
2016-10-17 07:42:15 SERVER -> CLIENT: 250-smtp-ca.example.org.uk 250-8BITMIME 250-SIZE 41943040 250 STARTTLS
2016-10-17 07:42:15 CLIENT -> SERVER: STARTTLS
2016-10-17 07:42:15 SERVER -> CLIENT: 220 Go ahead with TLS 
2016-10-17 07:42:16 SMTP Error: Could not connect to SMTP host.
2016-10-17 07:42:16 CLIENT -> SERVER: QUIT 
2016-10-17 07:42:16 SERVER -> CLIENT: 5Ul2̔4Oi6
2016-10-17 07:42:16 SMTP ERROR: QUIT command failed: 5Ul2̔4Oi6 
2016-10-17 07:42:16 Connection: closed'`

Here is what's on my PHPMailer for config. This works on a local microapache, but as soon as it goes on our IIS, no dice:

$mail->isSMTP();                                   

$mail->Host = 'smtp.example.org.uk';  // Specify main and backup SMTP servers

$mail->SMTPAuth = false;                               // Enable SMTP authentication

$mail->Port = 25;                                    // TCP port to connect to

$mail->setFrom('[email protected]', "example");

$mail->addAddress('[email protected]', 'B JONES');     // Add a recipient

$mail->Subject = 'Referral from: '.$_POST["staffName"]. '.';

$mail->AddEmbeddedImage('img/banner.jpg', 'banner');

$mail->AddEmbeddedImage('img/logo.jpg', 'logo');
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->IsHTML(true);

The rest of the PHP is just adding stuff to the body. (I've added in example to some lines, omitting smtp hosts and stuff.)


Solution

  • Firstly, you're using an old version of PHPMailer, so update it.

    Thre's nothing wrong with your script - it's an environment problem. Notice that it's failing as soon as it tries to use TLS. Have you have switched to PHP 5.6+ from an earlier version? That often causes this issue as PHP 5.6 and up enables certificate verification by default. The other common cause is that the OpenSSL extension is not enabled. Both are covered in the PHPMailer troubleshooting guide.