使用phpmailer发送异步电子邮件 [英] Send asynchronous email with phpmailer

查看:321
本文介绍了使用phpmailer发送异步电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用phpmailer发送异步电子邮件?

Is it possible to send asynchronous emails with phpmailer?

常规邮件发送代码段如下:

Regular mail sending code snippet is as follows:

$mail->Send();

PHP在继续之前等待Send()返回结果.可以让phpmailer立即返回结果,而无需等待真正的电子邮件发送例程完成.

PHP waits for the Send() to return the result before moving on. Is it possible to have phpmailer to return a result instantly without waiting for the real email sending routine to complete.

推荐答案

2016年5月更新

如用户 @Sinak Salek 所述,PHP确实支持多线程. 可以使用 pthreads 扩展名使用.

As mentioned by user @Sinak Salek PHP does support multithreading. It is available using the pthreads extension.

原始

PHP本身不支持多线程(您需要精美地完成此操作).您可以通过将电子邮件保存在数据库中,然后稍后使用其他脚本(例如,使用cron作业)进行处理来完成此操作.这样,您不必等待底层的电子邮件框架.

PHP does not support multithreading natively (which you need to do this beautifully). You can do it though by saving the emails in a database and then process them later using another script (e.g. using a cron job). In this way you don't have to wait for the underlying email framework.

另一件事,如果phpmailer速度很慢,可能是由于基础邮件程序(sendmail,postfix等)设置不正确所致.

Another thing, if phpmailer is slow it can be due to the underlying mail program (sendmail, postfix etc.) is setup incorrectly.

这篇关于使用phpmailer发送异步电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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