使用 PHPMailer() 发送电子邮件
我创建了一个时事通讯系统,我的问题是:考虑到我必须将该邮件发送到数百个电子邮件地址,我应该如何编写代码?
我和我的主机管理员讨论过,他告诉我应该一封一封地发送电子邮件,但每分钟不要超过 6 封。
我可以使用 $Timeout 属性吗?如果是这样,怎么办?
谢谢。
I have created a newsletter system and my question is: How should i write my code considering that i have to send that mail to hundreds of email addresses?
I've discussed with my host administrator and he told me that i should send my emails one by one but not more than 6 per minute.
Can i use the $Timeout property? If so, how?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您必须一封一封地发送邮件(而不是使用密件抄送),我会使用数据库队列来遵守每分钟仅发送 6 封邮件的限制(无论您最终使用哪种解决方案来实际发送邮件)发送邮件)。
例如,您有一个包含收件人、主题、邮件正文、最后发送日期、发送时间和状态的数据库表。
将要发送的所有邮件保存到数据库,然后设置一个每分钟运行一次的 cronjob,并检查队列中是否仍有邮件等待发送(例如,状态=“未发送”)。然后,您可以从队列中选择最多 6 封(或任何限制)邮件,将其发送出去,将状态设置为“发送”(并增加“timessent”并将“lastsenddate”设置为实际时间,如果您像)并等待下一个 cronjob,直到所有邮件都发送完毕。
这样您有几个优点:
If you have to send out the mails one by one (instead of using BCC), I'd use a database-queue to respect the limit of sending out only 6 mails per minute (no matter what solution you'll finally use to actually send the mails).
E.g. you'd have a database-table containing recipient, subject, mailbody, lastsenddate, timessent and status.
Save all mails, you will send out, to the database and then set up a cronjob that will run once a minute and check if there are still mails in the queue waiting to be send (e.g. status = "unsend"). Then you'd pick a maximum of 6 (or whatever your limit is) mails from the queue, send them out, set the status to "send" (and increase "timessent" and set "lastsenddate" to the actual time, if you like) and wait for the next cronjob until all mails are sent.
This way you have several advantages:
Pear Mail 将允许您从 PHP 向指定人员发送电子邮件。
http://pear.php.net/package/Mail/
Pear Mail will allow you to send email from PHP to allot of people.
http://pear.php.net/package/Mail/