通过PHPMailer发送电子邮件速度很慢 [英] Email through PHPMailer is slow

查看:947
本文介绍了通过PHPMailer发送电子邮件速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用phpmailer通过Gmail发送邮件时,该电子邮件要花费很长时间才能发送,有时也没有发送.我使用XAMPP作为本地主机.

When I am sending via Gmail using phpmailer, the email is taking a long time to send and also sometimes it is not going. I am using XAMPP as localhost.

这是我的代码:

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*/
}

推荐答案

我也有这个问题:这是因为PPHmailer与uniqid()一起创建了边界字符串,这在某些主机上非常慢.通过将2.参数more_entropy添加为true,我解决了该问题.

I had that too:It is because PPHmailer works with uniqid() to create its boundary strings, which, on certain hosts, is very slow. By adding the 2. parameter more_entropy to true, I solved that problem.

line 1379周围的文件class.phpmailer.php中:

public function CreateHeader() {
    $result = '';

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

来自文档

uniqid:

more_entropy

more_entropy

如果设置为TRUE,则uniqid()将添加附加的熵 (使用组合线性同余生成器) 返回值,这增加了结果将是

If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique.

这篇关于通过PHPMailer发送电子邮件速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆