问题描述
我使用phpmailer发送邮件,并且我想获取结果,因为发送邮件非常频繁.所以我想使用phpmailer"timeout".但是不起作用.我的代码
i use phpmailer to send mail,and i want to get the result,because send mail is very frequently. so i want to use phpmailer "timeout" .but is not working.my code
$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 = "[email protected]";
$mail->Password = "xxxx";
$mail->From = "[email protected]";
$mail->Subject = "This is the subject";
$mail->AltBody = "test";
//$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML("test233");
//$mail->AddReplyTo("[email protected]");
$mail->AddAddress("[email protected]");
$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
and echo is :1383181520 time out is 10 Message has been 1383181534
你能帮我吗
推荐答案
文档指出"var $ Timeout = 10设置SMTP服务器超时(以秒为单位)"和此功能不适用于win32版本."
The documentation states that "var $Timeout = 10 Sets the SMTP server timeout in seconds" and "this function will not work with the win32 version."
如果您想要更长的超时值,只需将其设置为一分钟(60秒)左右即可.如果要通过同一SMTP服务器发送多封电子邮件,则使连接保持打开状态,但请记住在最后将其关闭.
If you want a longer timeout value, simply set it to a minute (60 seconds) or so. If you are sending multiple emails through the same SMTP server, it may be beneficial to keep the connection open, but then remember to close it at the end.
如果您确实延长了超时时间,还请确保增加脚本上的时间限制,或将其全部删除:
If you do extend the timeout, also make sure that you increase the time limit on the script, or remove it all together:
<?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.
?>
这篇关于phpmailer超时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!