2013-10-31 86 views
1

我使用phpmailer发送邮件,我想得到结果,因为发送邮件非常频繁。所以我想使用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 = "[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/>"; 

和回音是: 1383181520超时是10消息一直1383181534

你能帮助我

+2

*“和回音是:1383181520超时是10消息一直1383181534 “* - 帮助什么?似乎它正在做它的工作。也许时间格式不是你所期望的。事实上你期待什么? –

+0

注意:更新版本的PHPMailer中的默认超时值为300秒= 5分钟。我还有一个2014版本,默认使用10分钟的超时时间。花了一段时间来追踪下来... – BurninLeo

回答

6

documentation指出:“变量$超时= 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. 
?>