Search code examples
phpsmtpphpmailerstarttls

EOF caught while checking if connected phpmailer


    require 'PHPMailerAutoload.php';

    $mail = new PHPMailer;
    $mail->SMTPDebug = 3;                               // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'myhost';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'myusername';                 // SMTP username
    $mail->Password = 'mypassword';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 1060;                                    // TCP port to connect to
    $mail->setFrom('[email protected]', 'test');
    $mail->isHTML(true); // Set email format to HTML


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

    for($i=0;$i<1;$i++){
      $mail->Subject    = "test bulk email ".$i;
      $mail->Body       = "this is email ".$i;


      if(!$mail->Send()) 
      {
          $error_message = "Mailer Error: " . $mail->ErrorInfo;
      }
}

echo $error_message;

When I run this code, I get this error:

Connection: opened 2018-03-05 09:24:25 SERVER -> CLIENT: 2018-03-05 09:24:25 SMTP NOTICE: EOF caught while checking if connected 2018-03-05 09:24:25 Connection: closed 2018-03-05 09:24:25 SMTP Error: Could not connect to SMTP host.

How do I fix this?


Solution

  • You're using an unusual port number for SMTP submission, so check you have the right one for your host. It would usually be 587 when using SMTPSecure = 'tls'.

    You're setting a gmail from address while sending through another host; that will cause you to fail SPF checks and your messages will either be blocked or spam filtered.

    If you want to send to a list, follow the mailing list example provided with PHPMailer - your code contains some mistakes that will probably result in duplicate messages.