在没有cron的情况下在后台发送邮件 [英] Send mails in background without cron

查看:74
本文介绍了在没有cron的情况下在后台发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以运行PHP循环,以便在后台向订阅者发送几百封电子邮件.我的目标是格式化新闻简报,单击发送,然后关闭浏览器或更改页面.当然,发送电子邮件的实际过程将在后台运行,并且不会因浏览器关闭而中断.

I was wondering if there is a way to run a PHP loop in order to send a few hundred emails to subscribers in background. My goal is to format the newsletter, click send and then close the browser or change page. Of course, the actual process of sending the e-mail will be running in background and would not be interrupted by the browser closing.

我知道这可以通过cron作业读取保存在MySQL或文本文件中的队列来完成,但是这样,即使很长一段时间没有队列,cron也会一直在运行,寻找该队列...

I know this can be made with a cron job reading from a queue saved in MySQL or text file, but this way, even if there is no queue for a long period, the cron will always be running, looking for the queue...

我已经在名为Pommo(https://github.com/soonick/poMMo)的脚本中看到了这种功能,但是似乎无法理解它是如何完成的.

I've seen this funcionality in a script called Pommo (https://github.com/soonick/poMMo) but can't seem to understand how it's done.

有人对此有想法吗?

推荐答案

我打算为您的问题添加评论,但是他们没有足够的空间来格式化和给出示例.

I was going to add a comment to your question, but them I didn't have enough space there to format and give the example.

我认为这是一个可行的想法:

Here is an idea I believe might work:

1-将所有要发送的电子邮件加载到数据库或文件中.

1 - Load all the emails you want to send to a database or file.

2-在Web应用程序中,单击按钮发送电子邮件.这将向服务器提交Ajax请求.您可以定义在特定时间范围内要发送的电子邮件数量.请记住,大多数主机对每小时可以发送的电子邮件数量有限制.

2 - From your web application click on the button to send emails. This will submit an Ajax request to the server. You can define the number of emails you want to send within a certain timeframe. Remember that most hosts have limits on number of emails you can send every hour.

3-创建一个PHP脚本,该脚本将接收Ajax请求并发送您定义的参数内的所有电子邮件.

3 - create a php script that will receive the Ajax request and send all the emails within the parameters you define.

4-我相信您可以杀死您的Web浏览器,因为PHP脚本将遍历整个列表,并且在完成发送所有电子邮件之前不会返回.

4 - I believe you can kill your web browser because the PHP script will run through the whole list and will not return until it finishes sending all the emails.

以上可能有效,但是我永远不会这样.我会如上所述使用cronjob.您的cronjob只需检查是否有要发送的电子邮件即可.这不是资源密集型.

The above might work, however I would never do it this way. I would use a cronjob as stated above. Your cronjob would only have to check if there are emails to send or not. This is not resource intensive.

如果您决定实施上述构想,请确保您告知我们.我很好奇这是否行得通.

If you decide to implement the ideas above, please make sure you let us know. I am curious if that would work.

祝你好运!

这篇关于在没有cron的情况下在后台发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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