phpmailer timeout not working

[亡魂溺海] 提交于 2019-12-08 04:57:33

问题


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   = "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/>";

and echo is : 1383181520 time out is 10 Message has been 1383181534

can you help me


回答1:


The documentation states that "var $Timeout = 10 Sets the SMTP server timeout in seconds" and "this function will not work with the win32 version."

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.
?>


来源:https://stackoverflow.com/questions/19696720/phpmailer-timeout-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!