从Zend Framework应用程序向数百个收件人发送电子邮件的最佳方法是什么? [英] What's the best approach to sending email to hundreds of recipients from a Zend Framework application?

查看:120
本文介绍了从Zend Framework应用程序向数百个收件人发送电子邮件的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序实现一个邮件列表系统。我正在使用 Zend_Mail_Transport_Smtp('localhost')作为我的传输,循环通过我的订阅者列表,并发送一个新的 Zend_Mail 给每一个。但是,我注意到脚本完成所需的时间长度随着用户数量的增加而增加。

I'm trying to implement a mailing list system for my application. I'm currently using Zend_Mail_Transport_Smtp('localhost') as my transport, looping through my list of subscribers, and sending a new Zend_Mail to each one. However, I am noticing that the length of time that it takes for the script to complete increases as the number of subscribers increase.

我确定必须有更多的专业的做法,涉及电子邮件的排队。我想,理想的方法是让用户填写表单,点击发送,并立即收到一封电子邮件正在发送的回复,而不是等待数百封电子邮件完成发送。

I'm sure there must be a more professional approach to doing this, involving the queuing of emails. I suppose the ideal approach would be for the user to fill out the form, click send, and immediately get a response saying that the emails are being sent, rather than waiting for the hundreds of emails to finish sending.

我明白,$ code> Zend_Mail 不做任何排序邮件排队。有谁有这方面的经验,给我一个如何做这个可以做的概述?我不知道有关cron / crontab / cronjobs的任何内容,所以如果涉及到这一点,请说明一下。

I understand that Zend_Mail does not do any sort mail queuing. Could anyone who has experience with this, give me an overview of how this can be done? I don't know anything about cron/crontab/cronjobs, so if it involves that, please explain the process.

推荐答案

为了使用PHP可靠地发送大量电子邮件,您必须使用排队机制。如其他人所建议的,使用队列的过程看起来像这样:

In order to reliably send a large number of emails using PHP you have to use a queueing mechanism. As suggested by others, the process of using a queue looks something like this:


  • 循环您的用户组,为每个用户创建一个电子邮件一个可能的自定义内容

  • 将每个邮件对象传递到队列,这将延迟发送电子邮件,直到稍后

  • 在某种cron脚本,一次发送队列的内容几百。注意:您需要通过观察实际发送过程中出现错误的日志来调整发送的电子邮件数量。如果您尝试发送太多,我注意到邮件传输将不再接受连接(我正在使用qmail)

  • Loop over your set of users, creating an email for each one and possibly customizing the content
  • Pass each mail object to the queue which will delay the sending of the email until later
  • In some sort of cron script, send out the contents of the queue a few hundred at a time. Note: you'll want to tweak the number of emails you are sending by watching the logs for errors coming back from the actual sending process. If you try to send too many, I've noticed it reaches a point where the mail transport will no longer accept connections (I'm using qmail)

您可以使用几个库来执行此操作, PEAR邮件队列(带Mail_Mime)和SwiftMailer都允许您创建和排队邮件。到目前为止,Zend Mail仅提供电子邮件的创建,而不是排队(稍后会有更多的)。

There are a few libraries out there you can use to do this, PEAR Mail Queue (with Mail_Mime) and SwiftMailer both allow you to create and queue emails. So far, Zend Mail only provides for creation of emails, not queueing (more on that later).

我主要以 PEAR邮件队列,还有一些问题。如果您正在排队大量的电子邮件(例如,循环超过20,000个用户,并尝试在合理的时间内将其排入队列),则使用Mail Mime的可引用打印编码实现非常慢。您可以通过切换到base64编码来加快速度。

I have experience primarily with PEAR Mail Queue and there are a few gotchas. If you are trying to queue up a large number of emails (for instance, looping over 20,000 users and trying to get them into the queue in a reasonable time), using Mail Mime's quoted-printable encoding implementation is very slow. You can speed this up by switching to base64 encoding.

对于Zend Mail,您可以编写一个Zend Mail Transport对象,将Zend Mail对象放入PEAR邮件队列。我已经取得了一些成功,但是需要花费一点时间来做到这一点。为此,扩展Zend Mail Transport Abstract,实现_sendMail方法(将Zend Mail对象放入到邮件队列中),并将传输对象的实例传递给Zend Mail对象的send()方法,或通过Zend Mail :: setDefaultTransport()。

As for Zend Mail, you can write a Zend Mail Transport object that puts your Zend Mail objects into the PEAR Mail Queue. I have done this with some success, but it takes a bit of playing to get it right. To do this, extend Zend Mail Transport Abstract, implement the _sendMail method (which is where you will drop your Zend Mail object into the Mail Queue) and pass the instance of your transport object to the send() method of your Zend Mail object or by Zend Mail::setDefaultTransport().

底线是有很多方法可以做到这一点,但它将代表您进行一些研究和学习。但是,这是一个非常可解决的问题。

Bottom line is that there are many ways you can do this, but it will take some research and learning on your behalf. It is a very solvable problem, however.

这篇关于从Zend Framework应用程序向数百个收件人发送电子邮件的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆