PHP 群发电子邮件最佳实践? (PHPMailer + Gmail)

发布于 2024-08-12 04:40:25 字数 631 浏览 1 评论 0原文

我正在考虑如何处理从我的网络应用程序发送大量电子邮件,以及是否有任何最佳实践。 StackOverflow 已经将其标记为“主观”,在某种程度上可能是这样,但我需要知道实现该系统的最成功的方法,或者是否存在任何标准化方法。

在我的 web 应用程序中,有一些用户是 1 到 10,000 个用户组的组长。该用户必须能够通过我的系统通过电子邮件向所有这些用户发送消息。因此,我的系统负责向每个组长的个人用户发送最多 10,000 封电子邮件。

据我所知,GMail 中向个人发送邮件没有速率限制(尽管最多有 500 个收件人)。

现在,我当前的设置是:

  • 当通过系统发送消息时,它会进入电子邮件队列。
  • cron 脚本每隔几分钟从队列中抓取消息,并发送这些电子邮件。
  • 所有电子邮件均通过 GMail 的 SMTP 服务器进行。
  • 实际执行邮件发送的应用程序是 PHPMailer。

随着用户群的增长,这种设置可能还不够。我的问题是:

  1. 我应该使用本地 SMTP 服务器吗?
  2. 我应该在本地计算机上使用邮件二进制文件吗?在这种情况下,我可能可以完全跳过队列?
  3. 有没有一种可以接受的方法来做到这一点?

谢谢!

I'm thinking about how to handle sending large amounts of email from my web applications, and whether there are any best practices for doing so. StackOverflow is already labeling this as 'subjective', which it may be to an extent, but I need to know the most successful way to implement this system, or whether any standardized approach exists.

In my webapp, there are users who are heads of groups of 1 to 10,000 users. This user must be able to email send a message to all of these users through my system. Therefore, my system is responsible for sending up to 10,000 emails to individual users for each group head.

As far as I can tell, there is no rate limit in GMail for sending messages to individuals (although there is a 500 recipient max).

Right now, my current setup is:

  • When a message is sent through the system, it enters an email queue.
  • A cron script grabs messages from the queue every few minutes, and sends out those emails.
  • All email is taking place through GMail's SMTP server.
  • The actual application doing the mailing is PHPMailer.

This setup, as the user base grows, will probably not suffice. The questions I have are:

  1. Should I be using a local SMTP server instead?
  2. Should I use a mail binary on the local machine instead? I this case, I could probably skip the queue altogether?
  3. Is there an accepted way to do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

离鸿 2024-08-19 04:40:25

谷歌应用程序引擎

我会在谷歌应用程序引擎(python)中编写这个,因为:

  • 它可以很好地扩展。
  • 它有一个很好的电子邮件 API。
  • 它有一个任务队列,有一个很好的 API 来访问它。
  • 因为Python是一门非常好的语言。
  • 它(相对)便宜。

PHP

如果我用 PHP 实现它,我会

  • 为自己找到一个好的 SMTP 服务器,它允许您发送这种数量的邮件,因为 Gmail 不允许您发送这种数量的邮件。我确信这会花费你一些钱。
  • 为自己找到一个像样的 PHP 电子邮件库来发送消息,例如像您所说的 PHPMailer。
  • 使用消息队列(例如 beanstalkd)将电子邮件放入队列并异步发送电子邮件。首先,因为这样用户将可以更快地加载页面。其次,使用像 beanstalkd 这样的消息队列,您可以更好地调节发送速度,这将防止您的电脑超载。您需要具有对服务器的 ssh 访问权限才能编译(安装)beanstalkd。您可以在 beanstalkd 找到 beanstalkd
  • 您还需要 ssh 访问权限才能在将处理消息队列的后台。 php beanstalkd-client 找到 beanstalkd-client

你可以在 php/apache/webpage 的

这是页面您将从中向用户发送消息。在此页面中,您将通过在以下行中进行编码来向 beanstalkd 发送消息:

// register Pheanstalk class loader
require_once('pheanstalk_init.php');
$pheanstalk = new Pheanstalk('127.0.0.1');
$message = ""; // This would contain your message
$pheanstalk->put(json_encode($message);

您必须使用 put 命令将消息放入消息队列中

从后台长期运行的 PHP 脚本:

代码看起来像这样:

// register Pheanstalk class loader
require_once('pheanstalk_init.php');
$pheanstalk = new Pheanstalk('127.0.0.1');

while(true) {
  $job =  $pheanstalk->reserve();
  $email = json_decode($job->getData());
  // Sent email using PHP mailer.
  $pheanstalk->delete($job);
}

就像我说的那样PHP 和 Google 应用程序引擎都可以实现,但我会选择应用程序引擎,因为它更容易实现。

Google App Engine

I would write this in Google app engine (python) because:

  • It scales well.
  • It has a good email api.
  • It has a taskqueue with a good api to access it.
  • Because python is a real nice language.
  • It is (relatively) cheap.

PHP

If I would implement it in PHP I would

  • Find yourself a good SMTP server which allows you to sent this volume of mails because Gmail will not allow you to sent this kind of volume. I am for sure that this will cost you some money.
  • Find yourself a decent PHP email library to sent messages with like for example PHPMailer like you said.
  • Use a message queue like for example beanstalkd to put email messages in queue and sent email asynchronously. First because with this the user will have snappier page load. Second with a message queue like beanstalkd you can regulate speed of sending better which will prevent from overloading your pc with work. You will need to have ssh access to the server to compile(install) beanstalkd. You can find beanstalkd at beanstalkd
  • You would also need ssh access to run a PHP script in the background which will process the message queue. You can find a beanstalkd-client at php beanstalkd-client

from php/apache/webpage

This is the page from which you will sent messages out to user. From this page you will sent message to beanstalkd by coding something in the lines of this:

// register Pheanstalk class loader
require_once('pheanstalk_init.php');
$pheanstalk = new Pheanstalk('127.0.0.1');
$message = ""; // This would contain your message
$pheanstalk->put(json_encode($message);

You have to put messages in message queue using put command

From long running PHP script in background:

The code would look something like this:

// register Pheanstalk class loader
require_once('pheanstalk_init.php');
$pheanstalk = new Pheanstalk('127.0.0.1');

while(true) {
  $job =  $pheanstalk->reserve();
  $email = json_decode($job->getData());
  // Sent email using PHP mailer.
  $pheanstalk->delete($job);
}

Like I am saying it is possible with both PHP and Google app engine but I would go for app engine because it is easier to implement.

夜无邪 2024-08-19 04:40:25

由于每天的电子邮件数量“高达”10,000 封,我不会依赖 GMail(或任何其他)SMTP。并不是说他们不能处理,显然他们可以处理更多。但他们可能不想这么做。

在我看来,拥有本地 SMTP 服务器是正确的方法:

  • 设置起来非常简单(只是不要让人们在没有强大的身份验证方案的情况下使用它)
  • 最现代的 MTA 很好地处理发送队列
  • 您不必与 GMail(或其他人)打交道,因为配额原因决定有一天阻止您的帐户

With an email count as "high" as 10.000 a day, I wouldn't rely on GMail (or any other) SMTP. Not that they can't handle it, obviously they can handle A LOT more. But they possibly don't want to.

Having a local SMTP server is IMO the way to go :

  • It's pretty easy to set up (just DON'T let people use it without a strong authent scheme)
  • Most modern MTA handle sending queues very well
  • You won't have to deal with GMail (or others) deciding to block your account someday for quota reasons
遥远的她 2024-08-19 04:40:25

Gmail 和 Google Apps 限制您每天最多发送 500 封电子邮件。我不确定这如何与最多 500 个收件人相结合,但如果您想发送 10,000 封电子邮件,您可能需要寻找另一个邮件服务器。我个人使用本地服务器或 ISP 或数据中心的 SMTP。

如果您要发送那么多电子邮件,我建议使用队列,这样用户就不会坐在那里等待电子邮件发送。

Gmail and Google Apps limits you to around 500 emails a day. I'm not sure how that combines with the 500 recipient max, but if you want to send 10 000 emails you'll probably want to find another mail server. I personally use a local server or the ISP or datacenter's SMTP.

If you are sending that many emails, I would recommend using the queue so the user's isn't sitting there waiting for the email to be sent.

向地狱狂奔 2024-08-19 04:40:25

请务必小心,不要将您的域作为垃圾邮件域列入黑名单。如果确实如此,您的大部分电子邮件、支持、销售等都会被屏蔽。这反过来可能会带来非常昂贵的费用。

您可能想使用 AWeber 之类的服务。它们不仅可以处理如此大量的电子邮件,而且还可以为您提供比您自己实现的更多的指标。

Be very careful that your domain doesn't get blacklisted as a spam domain. If it does, you can expect most of your emails to be blocked, support, sales, etc. Which could in turn be very expensive.

You may instead want to use a service like AWeber. Not only are they setup to handle these amounts of emails, but they can probably give you more metrics than you can implement on your own.

烦人精 2024-08-19 04:40:25

我不确定它是否在任何地方发布,但根据经验,我可以告诉您,如果您开始一次发送数百封邮件,Gmail 将会冻结您的帐户十五分钟左右。这件事上周发生在我身上。我认为您应该托管自己的 SMTP 服务器。使用 mail() 函数通常会将您的邮件放入某人的垃圾邮件文件夹中。

I'm not sure if it's publishe anywhere, but from experience I can tell you that Gmail will put a fifteen minute or so freeze on your account if you start sending hundreds of messages at a time. This happened to me last week. I think you should host your own SMTP server. Using the mail() function often will put your mail in someone's spam folder.

新人笑 2024-08-19 04:40:25

只需在本地计算机或同一 LAN 上的计算机上安装 Postfix 即可获得最大访问速度。确保它从外部牢固固定,并且可以从内部快速访问。

然后编写 PHP 脚本以将电子邮件直接注入到 Postfix 队列中。这将大大提高邮件传递的处理速度。

Just install Postfix on the local machine, or a machine on the same LAN for maximum access speeds. Make sure it is well secured from the outside, and quickly accessible from the inside.

Then code your PHP script to directly inject the emails to the Postfix queue. That shall dramatically increase the processing speed of mail delivery.

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