我使用phpmailer发送邮件,我想得到结果,因为发送邮件非常频繁。所以我想使用phpmailer“超时”。但是不工作。 我的代码
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Timeout = 10;
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "qinqin1920@gmail.com";
$mail->Password = "xxxx";
$mail->From = "qinqin1920@gmail.com";
$mail->Subject = "This is the subject";
$mail->AltBody = "test";
//$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML("test233");
//$mail->AddReplyTo("qinqin1920@gmail.com");
$mail->AddAddress("xxxx@qq.com");
$mail->IsHTML(true);
echo "<br/>".time()."<br/>";
echo "time out is ".$mail->Timeout."<br/>";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been";
}
echo "<br/>".time()."<br/>";
和echo是: 1383181520超时是10消息已经1383181534
你能帮帮我吗答案 0 :(得分:6)
documentation表示“var $ Timeout = 10以秒为单位设置SMTP服务器超时”和“此功能不适用于win32版本。”
如果您想要更长的超时值,只需将其设置为一分钟(60秒)左右即可。如果您通过同一个SMTP服务器发送多封电子邮件,那么keep the connection open可能会有所帮助,但请记得在最后关闭它。
如果确实延长了超时时间,还要确保增加脚本上的time limit,或者将它们全部删除:
<?php
set_time_limit(0); // remove a time limit if not in safe mode
// OR
set_time_limit(120); // set the time limit to 120 seconds
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Timeout = 60; // set the timeout (seconds)
$mail->SMTPKeepAlive = true; // don't close the connection between messages
// ...
// Send email(s)
$mail->SmtpClose(); // close the connection since it was left open.
?>