4

我使用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

你能帮助我吗

4

1 回答 1

9

文档指出“var $Timeout = 10 以秒为单位设置 SMTP 服务器超时”和“此功能不适用于 win32 版本。”

如果您想要更长的超时值,只需将其设置为一分钟(60 秒)左右。如果您通过同一个 SMTP 服务器发送多封电子邮件,保持连接打开可能会有所帮助,但请记住在最后关闭它。

如果您确实延长了超时,还请确保增加脚本的时间限制,或者将其全部删除:

<?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.
?>
于 2014-02-11T16:37:15.067 回答