PHPMailer发送邮件速度缓慢

3
当我使用phpmailer通过Gmail发送邮件时,邮件发送需要很长时间,有时甚至无法发送。我正在使用XAMPP作为本地主机。
以下是我的代码:
if($_POST['submit']{
/*MAIL PART BEGINS*/

        //error_reporting(E_ALL);
        error_reporting(E_STRICT);

        date_default_timezone_set('America/Toronto');

        require_once('class.phpmailer.php');
        //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

        $mail             = new PHPMailer();

        $body             = "Your Password has been generated.<p />";
        $body             .="New Password = '$password'<p />";
        $body             .="Please Login with your Employee ID and this password and you can change the password at any time.";
        //$body           .="Amount Requested = '$amount'<p />";
        //$body           .="Amount Sanctioned = '$amount_sanctioned'<p />";
        $body             = eregi_replace("[\]",'',$body);

        $mail->IsSMTP(); // telling the class to use SMTP
        $mail->Host       = "stmp.gmail.com"; // SMTP server
        $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
        $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
        $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
        $mail->Username   = "my_username@gmail.com";  // GMAIL username
        $mail->Password   = "******";            // GMAIL password

        $mail->SetFrom('my_username@gmail.com', 'First Last');

        $mail->AddReplyTo("my_username@gmail.com","First Last");

        $mail->Subject    = "Change Password";

        //$mail->AltBody    = "Hello...!!!"; // optional, comment out and test

        $mail->MsgHTML($body);

        $address = "$email"; 
        //$address1 = "my_username@gmail@hotmail.com";
        //$address2 = "my_username@gmail@rediffmail.com";
        //$address3 = "my_username@gmail@iicb.res.in";
        $mail->AddAddress($address, "First Last");
        //$mail->AddAddress($address1, "First Last");
        //$mail->AddAddress($address2, "First Last");
        //$mail->AddAddress($address3, "First Last");



        //$mail->AddAttachment("images/phpmailer.gif");      // attachment
        //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Message sent!";
        }
        //MAIL PART ENDS*/
}
1个回答

0
我也遇到过这个问题:这是因为PPHmailer使用uniqid()来创建其边界字符串,在某些主机上非常缓慢。通过将第二个参数more_entropy设置为true,我解决了这个问题。
在文件class.phpmailer.phpline 1379左右:
public function CreateHeader() {
    $result = '';

    // Set the boundaries
    $uniq_id = md5(uniqid(time(), true)); // adding 2. param more_entropy (true)
    // ....

来自文档

uniqid:

more_entropy

如果设置为TRUE,uniqid()将在返回值末尾添加额外的熵(使用组合线性同余发生器),从而增加结果唯一的可能性。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接