Search code examples
phpphpmailer

PHPMailer stuck on "Connection: opened"


Bellow is my code used to send an email. PHPMailer output messages are:

2019-01-19 13:47:42        Connection: opening to xxxxxx:465, timeout=5, options=array()  
2019-01-19 13:47:42     Connection: opened

I tried with a wrong password and nothing changes. Does anyone has an ideea what it may happen?

$mail = new PHPMailer();
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->SMTPDebug = 3;                                 // Enable verbose debug output
$mail->Host = 'xxxxxxx';                      // Specify main and backup SMTP servers
$mail->Port = 465;                                    // TCP port to connect to
$mail->SMTPAuth = true;                               // Enable SMTP authentication


$mail->Username = '[email protected]';            // SMTP username
$mail->Password = 'xxxxxxxx';                         // SMTP password



$mail->setFrom('xxxxxxxxxxx', 'xxxxxxx');
$mail->addAddress('xxxxx', 'xxxxx');                            // Add a recipient
$mail->addReplyTo('xxxxxxxxxx', 'xxxxxx');
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Timeout  =   5;
$mail->Subject = $subject;
$mail->Body    = $text;

$mail->send();

Solution

  • This is a code problem, not a network issue.

    You’re connecting to port 465, which is typically used for implicit TLS (i.e. it expects you to talk TLS immediately), known as SMTPS, but you have not told PHPMailer to do that, so it will just hang, as you’re seeing. Fix it by setting that TLS mode:

    $mail->SMTPSecure = 'ssl';