PhpMailer:加载一段时间,然后加载ERR_EMPTY_RESPONSE

时间:2015-02-25 21:16:48

标签: php email loading phpmailer

我正在处理一些奇怪的事情...... 我正在设置phpmailer,如果我有错误,我通常会收到错误

echo "Mailer Error: " . $mail->ErrorInfo;

实际上如果一切都很好,页面会加载一段时间,然后停止加载,输入chrome错误:ERR_EMPTY_RESPONSE(无法加载页面,因为服务器没有加载数据)

这是内容

<?php

$mail = new PHPMailer();

// set mailer to use SMTP
$mail->IsSMTP();

$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 645;
$mail->SMTPAuth = true;     // turn on SMTP authentication

$mail->Username = "myemail@gmail.com";  // SMTP username
$mail->Password = "my password"; // SMTP password

$email = 'myemail@gmail.com';
$mail->From = $email;

$mail->AddAddress("to@example.com", "Name");

$mail->WordWrap = 50;
$mail->IsHTML(true);

$mail->Subject = "Subject of the mail";

$mail->Body = "content";
$mail->AltBody = "content";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>

当然我已经包含了这些文件:

require_once('../library/class.phpmailer.php');
require_once('../library/PHPMailerAutoload.php');

2 个答案:

答案 0 :(得分:0)

两个错误 - 只需加载自动装带器,即可为您加载课程,这样就可以满足您的需求。

您已设置Port = 645;我怀疑你的意思是465。

对于Gmail,您应该关注the example from the docs:使用Port = 587SMTPSecure = 'tls'

答案 1 :(得分:0)

您需要将PHPMailer上传到6.5。 由于PHP 7.x它是不同的 看看代码有点变化