|
Posted by Manuel Lemos on 03/13/05 01:42
Hello,
on 03/11/2005 05:48 PM Redmond Militante said the following:
> i need some advice on making a bulk emailer script more robust.
>
> what i'm currently doing:
> -using mysql_fetcharray() to loop through an array of query results
> -for each iteration of the loop, get an email address from the current row in the result set, and use it with the mail() function to send out an individual email to that email address, then echo out a confirmation in HTML so that the user will know that an email has been sent
> -this is repeated for each email address found in the result set
> problem with this is: with large result sets (some of my result sets come up with a few thousand email addresses), users have to wait a long time for the confirmation messages to print out to their browser, sometimes it seems that not all the messages go through
>
> what i've tried:
> -using mysql_fetcharray() to loop through an array of query results
> -for each iteration of the loop, get an email address from the current row in the result set, and append it to a long strong called $bcc
> -then i plug the value of $bcc into the mail() command, which is
issued only once at the end of the loop
This is a bad idea because many mail systems like hotmail will classify
as junk messages that do not come with the actual recipient address in a
visible header: To: or Cc: .
> -this method seems to work better, does not take as long, HTML confirmation messages get printed faster since mail() function is only called once at the end of the loop, only one email is sent (with a long BCC field), so it doesn't bog the server down so much
> problem with this method is: with large result sets (some of my result sets come up with a few thousand email addresses), the BCC field is so large that it is too large for the mail server to send out
>
> has anyone done a bulk emailer script to send out mass emails? if you have any advice re: methodology, i'd like to hear it.
It depends on what type of MTA.
There is no way to do bulk mailing properly and and avoid long waits.
You need to send separate messages to each recipient due to the problem
mentioned above.
For starters, just stay away from SMTP based solutions if you can. It
works but it takes much longer to queue messages that some alternatives
because you need to deal with TCP overhead, which is silly when your MTA
is in the same machine.
The best alternative is to inject the messages in the local mailer queue
and tell it to no start delivering the messages immediately.
If you can use sendmail (or exim ) there are some switches for the
sendmail command for that purpose. Using qmail or postfix does not
require any switches.
In any case, you may want to try this MIME message composing and sending
class. It provides several means to optimize bulk deliveries,
personalized or not. You can pick a sub-class to optimize deliveries for
the MTA that you use. There are sub-classes for mail, sendmail (or exim
or postfix), qmail, SMTP or Windows pickup folder are supported.
Regardless of which you use, always call SetBulkMail() function before
start looping deliveries to your users.
If you are not personalizing message, you can tell the class to cache
message bodies between deliveries to avoid message regeneration overhead.
If you want to personalize messages, you can even use Smarty as template
engine to speedup personalized message generation.
There are several examples to demonstrate this:
http://www.phpclasses.org/mimemessage
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/
Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Navigation:
[Reply to this message]
|