You are here: Re: bulk emailer « PHP « IT news, forums, messages
Re: bulk emailer

Posted by Matthew Weier O'Phinney on 03/12/05 20:48

* Redmond Militante <r-militante@northwestern.edu>:
> 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 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 d= oesn'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.

Don't do this from a browser. While it seems like a good idea, the
larger your dataset gets, the more likely it is that you'll either (a)
exceed PHP's memory limit, and/or (b) exceed PHP's maximum execution
time, and/or (c) have a user inadvertently close the browser, their OS,
or experience a crash (thus interrupting execution of the script).

The better way is to have your mailer simply activate a status flag
indicating a mailing is ready, then have another script on the server
waiting for such an event (or a cronjob that scans for such flags)
perform the actual mailing.

I agree with Richard regarding mail(). Your server-side script that
performs the mailing should probably do an SMTP connection to your mail
server. It should also either write to a log or send confirmation to the
admin who executed the send command indicating how many mails were sent
(and any errors that occurred).

I run a bulk mailer for my company (non-profit company mailing to
opt-ins -- not spam!), and we do NOT use PHP for the actual mailing
daemon; we use perl. Perl has several modules that allow for tight
integration with a variety of mail servers, as well as the ability to
easily for processes -- meaning we can send multiple mails
simultaneously. However, in essence, we're doing much as you describe,
with one twist -- we're pulling a result set and looping over the
results, but instead of creating one long BCC string, we send one email
at a time. Emails are sent to our mail server, which can then queue them
up -- meaning that the script can run as fast as it can send them (based
on the number of processes we allow). The email server then spits them
out at its own rate (and we can even manage the queue while it's in
process).

Our admin frontends, however, *are* PHP -- which gives us a nice, easy
to maintain frontend to list administration.

This is another place where I agree with Richard -- it's probably best
to utilize a third-party mailing list management software instead of
rolling your own. They will have ironed out these bugs already, and are
specially tuned for this sort of operation.

--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация