如何使用定时器批量发送电子邮件?
假设我的数据库中有 200 个用户,并且当前托管在共享主机上。我想向他们发送简讯,并且每 5 分钟仅发送 10 封电子邮件。
我将使用 phpmailer 发送新闻通讯。问题..
- 使用现有数据库发送新闻通讯而不将其导出到第三方服务的好概念是什么?
- 确保脚本不会同时发送重复的新闻通讯的关键是什么?
- 实现我的目标的良好做法是什么?
让我知道
Let's say I have 200 users in my database and currently host on shared hosting. I want to send a newsletter to them and send only 10 emails every 5 minutes.
I'll send the newsletter using phpmailer. Questions..
- What is the good concept to send a newsletter using existing database without export it to 3rd party services?
- What is the key to make sure script will not send duplicate newsletter in same time?
- What is the good practice to achieve my goal.
Let me know
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该只使用具有良好 API 的 3d 方服务。从长远来看,工作量会少得多。
您没有考虑过退回邮件处理、取消订阅、域密钥、避免黑名单等等。
最好的情况是您的邮件最终会进入垃圾邮件箱。
最糟糕的是,您的 IP 将被禁止,您的帐户将因发送未经请求的电子邮件而被终止(您的 ISP 不会关心他们是否真的注册了)。
You should just use a 3d party service with a good API. It will be much less work in the long run.
You haven't thought about bounce handling, unsubscribe, domain keys, avoiding blacklists and more.
At best your messages will end up in the junk mail box.
At worse your IP will be banned and your account terminated for sending unsolicted email (Your ISP won't care if they actually signed up for it).
设置一个任务,从数据库中选择固定数量的未发送新闻通讯(我会删除已发送的新闻通讯或将它们标记为已发送,或将它们移动到另一个表)。在您的情况下,您显然希望每 5 分钟发送 10 封电子邮件,因此将任务设置为获取 10 封电子邮件并发送它们。然后设置一个 cron 并让它每五分钟运行一次...如果您只计划每周发送一次/两次电子邮件,那么可能有一个更优雅的解决方案。您可以使用 sleep 命令执行一些 while 循环,但这并不是特别有效的资源效率......我只想采用上面的方法 - 它可能是最灵活的强力解决方案,并且您的主机不会真正注意到,因为它仍然会相对较快。
Set up a task to select a fixed number of un-sent newsletters from the database (I would either delete sent newsletters or mark them as sent, or move them to another table). In your case you're obviously wanting to send 10 every 5 minutes, so set the task to fetch 10 emails, and send them. Then set up a cron and have it run every five minutes... There's probably a more elegant solution though if you're only ever planning on sending out the emails once / twice a week. You could do some while loops with a sleep command but thats not particularly resource efficient.... I would just go with the above - its probably the most flexible brute force solution, and your host won't really notice as it'll still be relatively quick.