PHPMailer停留在“连接:已打开”

时间:2019-01-19 13:53:45

标签: php phpmailer

以下是我用来发送电子邮件的代码。 PHPMailer输出消息为:

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

我尝试使用错误的密码,但没有任何变化。有谁对这件事有想法?

$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 = 'xxxxxxxx@xxx.xxx';            // 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();

2 个答案:

答案 0 :(得分:0)

问题,而不是网络问题。

您正在连接到465端口,该端口通常用于隐式TLS(即,您希望您立即与TLS通讯),即SMTPS,但您并未告诉PHPMailer这样做,因此它将挂起,因为你看到了。通过设置TLS模式来解决此问题:

$mail->SMTPSecure = 'ssl';

答案 1 :(得分:0)

这个答案使我免于陷入完全相同的问题。 我正在查看的所有示例都有:

$mailer->SMTPSecure = 'tls';

将该行更改为:

$mailer->SMTPSecure = 'ssl';

消息没问题。