使用Office 365 SMTP加速PHPmailer [英] Speed up PHPmailer with office 365 smtp

查看:263
本文介绍了使用Office 365 SMTP加速PHPmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPMailer通过office365帐户从服务器发送邮件.

I am using an PHPMailer to send mail from my server through an office365 account.

但是,发送电子邮件似乎大约需要10到12秒,这使客户不耐烦,他们再次单击发送"按钮.

However it seems to take about 10-12 seconds to send the email, and this is making customers impatient and they are clicking the send button again.

这是我的代码

$mail->IsSMTP();                                // enable SMTP
$mail->SMTPAuth     = true;                     // turn on SMTP authentication
$mail->SMTPSecure   = "tls";                    // Secure type = tls
$mail->Host         = "smtp.office365.com";     // Hostname
$mail->Username     = "user@domain.co.uk";      // Username
$mail->Password     = "password";            // Password
$mail->Port         = 587;                      // Office 365 Port

$mail->IsHTML(true);
$mail->setFrom('online@domain.co.uk','Website Email');
$mail->AddReplyTo("sales@domain.co.uk","Sales");
$mail->AddAddress($value);
$mail->Subject($subject);
$mail->Body($body);
if(!$mail->Send()) {
     $string = date('Y-m-d').','.date('H:i:s').','.$mail->ErrorInfo;
     $this->writetolog('mailLog',$string);
 } else {
      echo "Message sent!";
 }

邮件发送正确,但是发送它只花了很长时间.

The message is sending correctly but it just takes so long to send it.

这是常见的事情还是我可以做些什么来完全加快这个过程.

Is this a common thing or there something I can do to speed the process up at all.

在我使用smtp并从服务器发送消息之前,它是即时的,但是客户有时会将邮件放入垃圾箱等中,而且看起来并不专业.

Before i was using the smtp and just sending from the server it was instant but customers were sometimes getting the mail into junk boxes etc and they did not look professional.

非常感谢.

推荐答案

感谢您的帮助,

为了解决这个问题,我决定将电子邮件存储到数据库中. 然后,每隔2分钟,我会执行一项cron作业,以清除邮件队列并使用交换smtp发送邮件

To get over the problem i decided to store the email into a database. Every 2 minutes i then run a cron job to clear the mail queue and send using the exchange smtp

如果在后台停留10到12秒,则不会破坏我的客户体验.

If it take 10-12 seconds behind the scenes it has not ruined my customer experience.

这篇关于使用Office 365 SMTP加速PHPmailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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