使用 PHP 发送大量电子邮件
我目前正在写一个音乐博客。 管理员每 2-3 天发布一篇新文章。 一旦管理员发布文章,就会立即向大约 5000 名订阅者发送大量电子邮件。
实现群发邮件功能的最佳方式是什么?
下面这个函数能用吗?
function massmail()
{
$content = '...';
foreach ($recipients as $r) {
$_content = $content . '<img src="http://xxx/trackOpenRate.php?id='.$r.'">';
mail($r, 'subject', $_content);
}
}
另一个问题:如果所有 5000 个订阅者都使用 Yahoo Mail,Yahoo 是否会将其视为 DDOS 攻击并阻止我的 SMTP 服务器的 IP 地址?
I am currently writing a music blog. The administrator posts a new article every 2-3 days. Once the administrator posts an article, a mass email will be sent to around 5000 subscribers immediately.
What is the best way to implement the mass mail feature?
Does the following function work?
function massmail()
{
$content = '...';
foreach ($recipients as $r) {
$_content = $content . '<img src="http://xxx/trackOpenRate.php?id='.$r.'">';
mail($r, 'subject', $_content);
}
}
Another question: If all 5000 subscribers are using Yahoo Mail, will Yahoo treat it as a DDOS attack and block the IP address of my SMTP server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
这是建议,而不是答案:使用专用的邮件列表软件会更好。 mailman 是一个经常使用的示例,但就像 mlmmj 可能就足够了。 发送群发邮件实际上是一项比实际看起来更困难的任务。 您不仅必须发送邮件,还必须跟踪“死”地址,以避免您的邮件,或更糟糕的是,您的邮件服务器被标记为垃圾邮件。
您必须处理出于同样原因取消订阅的人。
您可以自己实现这些事情,但特别是反弹处理是一项困难且无回报的工作。 使用邮件列表管理器将使事情变得更加容易。
至于如何让你的邮件适合雅虎,那就完全是另一回事了。 尽管存在种种缺陷,他们似乎还是非常看重 SPF 和 DomainKey。 您可能必须实施它们,这需要邮件服务器管理员的合作。
This is advice, not an answer: You are much, much better off using dedicated mailing list software. mailman is an oft-used example, but something as simple as mlmmj may suffice. Sending mass mails is actually a more difficult task than it actually appears to be. Not only do you have to send the mails, you also have to keep track of "dead" addresses to avoid your mail, or worse, your mailserver, being marked as spam.
You have to handle people unsubscribing for much the same reason.
You can implement these things yourself, but particularly bounce handling is difficult and unrewarding work. Using a mailing list manager will make things a lot easier.
As for how to make your mail palatable for yahoo, that is another matter entirely. For all its faults, they seem to put great stock in SPF and DomainKey. You probably will have to implement them, which will require co-operation from your mail server administrator.
您可以考虑使用 CRON 来执行此类操作。 一次发送大量邮件肯定不好,它可能会被检测为垃圾邮件、DDoS、使服务器崩溃等。
因此,CRON 可能是一个很好的解决方案,一次发送 100 封邮件,然后等待几分钟,再发送 100 封邮件,等等。
You may consider using CRON for that kind of operation. Sending mass mail at once is certainly not good, it may be detected as spam, ddos, crash your server etc.
So CRON could be a great solution, send 100 mails at once, then wait a few minutes, next 100, etc.
不要使用标准 PHP 工具向 5,000 人发送电子邮件。 您将在几秒钟内被大多数 ISP 禁止,而您甚至不知道这一点。 您应该使用某些邮件列表软件或电子邮件服务提供商执行此操作。
Do not send email to 5,000 people using standard PHP tools. You'll get banned by most ISPs in seconds and never even know it. You should either use some mailing lists software or an Email Service Provider do to this.
为什么不使用phplist? 它也是建立在 PHP Mailer 之上的,许多行业领导者都在使用它。 我自己曾多次使用它向我的客户发送大量邮件。 phplist 的好处是您可以在域级别和时间限制级别上限制消息。
我们还使用我们拥有的几个内部捕获系统将我们的用户群推送到邮件列表,然后让 cron 条目每天触发给定的邮件。 可能性是无限的,这就是开源的伟大之处!
Why don't you rather use phplist? It's also built on top of PHP Mailer and a lot of industry leaders are using it. I've used it myself a couple of times to send out bulk mails to my clients. The nice thing about phplist is that you can throttle your messages on a domain level plus a time limit level.
What we've also done with a couple of internal capture systems we've got was to push our user base to the mailling list and then have a cron entry triggering a given mail each day. The possibilities are endless, that's the awesome thing about open source!
还有 Pear 包:
http://pear.php.net/package/Mail_Mime
http://pear.php.net/package/Mail
http://pear.php.net/package/Mail_Queue
呜呜。
PS:不要使用 mail() 发送这 5000 封电子邮件。 除了其他人所说的之外,它的效率极低,因为 mail() 为每个电子邮件集创建了一个单独的套接字,即使对于同一个 MTA 也是如此。
Also the Pear packages:
http://pear.php.net/package/Mail_Mime
http://pear.php.net/package/Mail
http://pear.php.net/package/Mail_Queue
sob.
PS: DO NOT use mail() to send those 5000 emails. In addition to what everyone else said, it is extremely inefficient since mail() creates a separate socket per email set, even to the same MTA.
另请查看 PHPmailer 类。 PHPMailer
Also have a look at the PHPmailer class. PHPMailer
您可以使用 swiftmailer 来实现。 通过使用批处理。
You can use swiftmailer for it. By using batch process.
我已经使用
Lotus Notus
和PHP
做到了。如果您有权访问邮件服务器或者可以向
邮件服务器
管理员请求某些内容,则此解决方案有效:1) 在
邮件服务器
中创建一个组:销售部门2) 将您需要加入该组的帐户分配给
组
3) 为该组分配一个互联网地址:
[email protected]
4) 使用邮件功能创建 PHP 脚本:
< br>
它对我有用,该组中包含的所有帐户都会收到邮件。
祝你好运。
I already did it using
Lotus Notus
andPHP
.This solution works if you have access to the mail server or you can request something to the
mail server
Administrator:1) Create a group in the
mail server
: Sales Department2) Assign to the
group
the accounts you need to be in the group3) Assign an internet address to the group:
[email protected]
4) Create your PHP script using the mail function:
It worked for me and all the accounts included in the group receive the mail.
The best of the lucks.
除了使用软件之外,还有更多内容。 如果您可以创建一个间歇性发送的批量电子邮件程序。 假设您要发送 5,000 个收件人,请创建一个循环,每次发送发送 38 个列表,然后暂停 10 秒。 在过去的几周里,我有过每天手动发送 500 个邮件的实际经验,到目前为止,我取得了良好的结果。
另一个考虑因素是电子邮件的内容。 如今,您需要输入您的实际办公室地址并选择“取消订阅”,这已成为一种标准。 这些是大多数收件人电子邮件服务器正在检查的因素。 如果您没有这些,他们会将您归类为垃圾邮件发送者。
如果您希望付费服务提供商向您的电子邮件订阅者发送而不是发送未经请求或冷淡的营销电子邮件,Mailchimp 是我的最佳推荐。
希望能帮助到你。
There is more into it aside from using a software. If you could create a bulk emailer program that sends intermittently. Say if you will send 5,000 recipients, create a loop that would send 38 lists per sending then pause for 10 seconds. I have an actual experience sending 500 manually per days for the past weeks and so far i have good results.
Another consideration are the content of your email. Nowadays it is a standard that you need to put your physical office address and the "unsubscribe" opt-out. These are factors that majority of recipient emails servers are checking. If you don't have these they will classify you as spammer.
Mailchimp is my best recommendation to use if you want a paid service provider in sending to your email subscriber NOT sending unsolicited or cold email marketing.
Hope it helps.
首先,使用 PHP 自带的 mail() 函数并不是一个最佳的解决方案。 它很容易被标记为垃圾邮件,您需要设置标头以确保正确发送 HTML 电子邮件。 至于代码片段是否能工作,它会工作,但我怀疑如果没有 指定额外的标头
我建议您看一下SwiftMailer,它具有 HTML 支持,支持不同的 mime 类型和 SMTP 身份验证(这不太可能将您的邮件标记为垃圾邮件)。
First off, using the mail() function that comes with PHP is not an optimal solution. It is easily marked as spammed, and you need to set up header to ensure that you are sending HTML emails correctly. As for whether the code snippet will work, it would, but I doubt you will get HTML code inside it correctly without specifying extra headers
I'll suggest you take a look at SwiftMailer, which has HTML support, support for different mime types and SMTP authentication (which is less likely to mark your mail as spam).
我会将所有电子邮件插入数据库(有点像队列),然后像您在代码中所做的那样一次处理一封电子邮件(如果您想使用 swiftmailer 或 phpmailer 等,您也可以这样做。
)每发送一封邮件,更新数据库以记录发送的日期/时间。
通过首先将它们放入数据库中,您可以
请记住,如何自动执行退回的电子邮件或无效的电子邮件,以便将它们自动从你的清单。
如果您发送那么多电子邮件,您肯定会收到一些退回邮件。
I would insert all the emails into a database (sort of like a queue), then process them one at a time as you have done in your code (if you want to use swiftmailer or phpmailer etc, you can do that too.)
After each mail is sent, update the database to record the date/time it was sent.
By putting them in the database first you have
Keep in mind, how to automate bounced emails or invalid emails so they can automatically removed from your list.
If you are sending that many emails you are bound to get a few bounces.