What's the best approach to sending email to hundreds of recipients from a Zend Framework application?

前端 未结 8 1011
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 08:44

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

相关标签:
8条回答
  • 2020-12-29 09:30

    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:

    • 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)

    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).

    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.

    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.

    0 讨论(0)
  • 2020-12-29 09:36

    You should be fine using PHP up into the thousands of recipients, although avoid the mail() as others have noted. I've seen a few systems designed for large amounts of mail (100,000+ recipients) kick over to bypassing the standard mailing functions and trying to work more directly with the MTA. Even then it's not been clear to me that was required.

    Making email professional is more about making sure the formatting is good (HTML and plain text whenever possible), people can unsubscribe easily, bounces are handled correctly, the mail server has all the right DNS records are in place, and the server configuration doesn't violate rules of any major blacklist system. The language you write the application in isn't a major factor at a few hundred or even a few thousand messages.

    0 讨论(0)
提交回复
热议问题