在PHP中创建邮件队列? [英] Creating an email queue in PHP?

查看:138
本文介绍了在PHP中创建邮件队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个这样的报价系统:

I am currently creating a quote system which works like this:


用户通过表单发送数据 - >发送到db的数据 - - > pdf生成 - >发送电子邮件

User submits data through form --> data sent to db --> pdf generated --> email sent

我正在使用 htmlmimemail5 图书馆做这个和生成的电子邮件发送到本地网络上单独服务器上的邮件交换。

I am using the htmlmimemail5 library to do this and the email generated is sent to a mail exchange on a separate server on the local network.

令人遗憾的是,PHP的脚本需要大约一分钟才能完全执行,因为脚本等待来自MX的确认邮件已发送或已发送失败。

Sadly the negative side of this is that the php script takes around a minute to fully execute as the script waits for confirmation from the MX that the email has been sent or has failed.

所以我希望有可能是一个单独的PHP应用程序处理所有的电子邮件处理,意味着用户不必等待一分钟并且可以跳转到他们可以查看信息等的下一个页面。

So what I was hoping would be possible is to have a separate PHP application that handles all the email processing and means that the user does not have to wait a minute and can instead jump to the next page where they can view information etc.

此应用程序将很乐意处理已从用户进程请求中构建的邮件队列,如果队列是空的可能会关闭?

This application would happily work away on an email queue that has been built up from user process requests and if the queue is empty would possibly shut down?

我猜想这将需要一些电子邮件队列(如打印队列)。

I'm guessing it would need to be some sort of email queue (like a print queue).

然而,因为我是一个初级的PHP开发人员,所有其他的开发人员都太忙了,不能保姆,我完全失去了,甚至不知道从哪里开始,正确的策略?

However, because I am a junior PHP dev and all the other devs are too busy to babysit, I am completely lost and do not even know where to begin from or if this is even the right strategy?

更多信息:


  • 服务器是一个BSD监狱

  • Apache 2.2 / PHP5

所有内部和外部电子邮件都通过POSTINI路由,这也增加了延迟。

All internal and external emails are routed through POSTINI, which adds a delay as well.

任何想法或建议欢迎! :)

Any ideas or suggestions welcome! :)

推荐答案

是的,这是非常直接的实现。而不是立即发送,将电子邮件数据保存到数据库。有一个脚本(每分钟通过cron运行,或者更好地运行一个守护程序PHP脚本)取消排队的电子邮件并将其发送出去。

Yep, this is pretty straightforwards to implement. Rather than immediately sending, save the e-mail data to a database. Have a script (running every minute via cron, or better yet a daemonized PHP script) that takes the queued e-mails and sends them out.

确保在数据库中有标志来指示进度,即发送列,另一个用于发送,所以你的脚本知道不要尝试重复发送已经发送的一个。

Be sure to have flags in your database to indicate progress, i.e. a column for "sending" and one for "sent", so your script knows not to try to repeatedly send one that's already in the process of being sent.

这篇关于在PHP中创建邮件队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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