2013-10-31 89 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. 
?>