PHP Mailer taking over 30 seconds to send a welcome email

大城市里の小女人 提交于 2019-12-02 00:21:39

Remote SMTP is not really a good thing to use during page submissions - it's often very slow (sometimes deliberately, for greetdelay checks), as you're seeing. The way around it is to always submit to a local (fast) mail server and let it deal with the waiting around, and also handle things like deferred delivery which you can't handle from PHPMailer. You also need to deal with bounces correctly when going that route as you won't get immediate feedback.

That you can often get away with direct delivery doesn't mean it's a reliable approach.

To see what part of the SMTP conversation is taking a long time, set $mailer->SMTPDebug = 2; and watch the output (though don't do that on your live site!).

Don't know if PHPMailer is compulsory for you or not, but if it's not I am recommanding SwiftMailer .

as per my personal Experience It's Really fast and reliable.

Thanks.

include_once "inc/swift_required.php";

$subject = 'Hello from Jeet Patel, PHP!'; //this will Subject
$from = array('jeet@mydomain.com' =>'mydomain.com'); //you can use variable

$text = "This is TEXT PART";
$html = "<em>This IS <strong>HTML</strong></em>";

$transport = Swift_SmtpTransport::newInstance('abc.xyz.com', 465, 'ssl');
$transport->setUsername('MYUSERNAME@MYDOMAIN.COM');
$transport->setPassword('*********');
$swift = Swift_Mailer::newInstance($transport);



    $to = array($row['email']  => $row['cname']);
    $message = new Swift_Message($subject);
    $message->setFrom($from);
    $message->setBody($html, 'text/html');
    $message->setTo($to);
    $message->addPart($text, 'text/plain');

    if ($swift->send($message, $failures))
    {
        echo "Send successfulllyy";
    } else {
        print_r($failures);

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