Send asynchronous email with phpmailer

▼魔方 西西 提交于 2019-12-19 05:48:26

问题


Is it possible to send asynchronous emails with phpmailer?

Regular mail sending code snippet is as follows:

$mail->Send();

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.


回答1:


Update May 2016

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

Original

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.

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




回答2:


If you're on linux, you can put your php script in an exec command and launch it in background (put an & at the end of the command) and silent mode (2>&1 >/dev/null)



来源:https://stackoverflow.com/questions/9342214/send-asynchronous-email-with-phpmailer

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