使用 PHPMailer() 发送电子邮件

发布于 2024-08-21 23:03:01 字数 162 浏览 10 评论 0原文

我创建了一个时事通讯系统,我的问题是:考虑到我必须将该邮件发送到数百个电子邮件地址,我应该如何编写代码?

我和我的主机管理员讨论过,他告诉我应该一封一封地发送电子邮件,但每分钟不要超过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤浅笑 2024-08-28 23:03:01

如果您必须一封一封地发送邮件(而不是使用密件抄送),我会使用数据库队列来遵守每分钟仅发送 6 封邮件的限制(无论您最终使用哪种解决方案来实际发送邮件)发送邮件)。

例如,您有一个包含收件人、主题、邮件正文、最后发送日期、发送时间和状态的数据库表。

将要发送的所有邮件保存到数据库,然后设置一个每分钟运行一次的 cronjob,并检查队列中是否仍有邮件等待发送(例如,状态=“未发送”)。然后,您可以从队列中选择最多 6 封(或任何限制)邮件,将其发送出去,将状态设置为“发送”(并增加“timessent”并将“lastsenddate”设置为实际时间,如果您像)并等待下一个 cronjob,直到所有邮件都发送完毕。

这样您有几个优点:

  1. 您可以遵守每分钟的限制
  2. 您将所有邮件都存储在数据库中,并且可以稍后与它们关联(例如,找出您上周五发送了多少邮件以及哪些邮件,或者查找 -
  3. 通过跟踪邮件状态,您可以实现一个退回处理程序,例如设置邮件 如果邮件返回,状态为“退回”,因此您可以稍后开始重新发送邮件,以通过
  4. 将邮件保存到数据库来到达第一次返回“邮箱已满”消息的地址,您甚至可以设置一个通过添加数据库字段“开始时间”来“延迟邮件服务”并使您的发送脚本尊重这个日期,这样您就可以在春天排队您的圣诞邮件了:)

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:

  1. you can respect your per-minute-limit
  2. you have all your mails in a database and can relate to them later (e.g. to find out how many mails - and which ones - you sent last Friday or to find out whether a certain address has been processed - and when and how many times - if someone claims he never received a mail / or too many)
  3. by tracking a mail-status you could implement a bounce-handler that'll e.g. set a mail-status to "bounced" if a mail returns, so you could start a resend of your mailing some time later to reach addresses that returned a "mailbox full"-message the first time
  4. by saving your mails to a database, you could even setup a "deferred mail service" by adding a database-field "starttime" and make your send-script respect this date, so you could already queue your Christmas-mails in spring :)
来世叙缘 2024-08-28 23:03:01

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文