Best method of bulk sending email newsletters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PaulCreedy
Forum Newbie
Posts: 6
Joined: Mon May 19, 2003 4:30 am

Best method of bulk sending email newsletters

Post by PaulCreedy »

I would like to bulk send a newsletter to subscribers to my site. I currently do this on my local machine by downloading the list and using a desktop app to send the newsletter from my computer.

My host isn't so keen on bulk sending from the host because of the CPU load, etc. and the possibility that some sites may see a bulk send as spam and block the IP.

I'm looking for recommendations on the most efficient way of sending mail from the site and the pro's and con's of the different methods. ie Looping through each mail and sending individually, BCC sending, mailing list servers, etc.

I'm an ASP to PHP convert, so I'm still in the learning stage of PHP, but I can use the mail() function.

What methods do you use/recommend?

Thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ask your provider wether they are willing to install a group list for you (or already have).
That way you would maintain a list of group members and send your newsletter to this group. The server will handle the recipient list which might take less performance.
Always include a working unscribe link and ask your provider wether common X-headers for spam spoofing are enabled
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Well here's the code I use, inspired by similar code in the SourceForge.Net 2.5 baseline (before they changed from GPL to closed-source). On my site I use this for allowing the people running a given hosted event to broadcast a message to their event attendees. (Often in the 200-400 people range)

Code: Select all

function spamList($addresses,$subject,$body,$from,$headers="")
{
  global $CIB_HOSTNAME, $CIB_DOMAIN, $CIB_SERVER_ADMIN_EMAIL;
  $addresses = array_unique($addresses);
  $numAddresses = count($addresses);
  $to = "no-reply@$CIB_HOSTNAME{$CIB_DOMAIN}";
  $bcc = "";
  $body .=<<<END_TAGLINE
\n\nThis message is sent to you through the competitor notification
service of the CompInaBox server running at $CIB_HOSTNAME{$CIB_DOMAIN}.   Use for any
purpose unrelated to the competition in question is strictly prohibited.
Please notify the server administrator at $CIB_SERVER_ADMIN_EMAIL to report
abuse.
END_TAGLINE;
  if ($headers!="")    $headers="X-mailer: CompInaBox via PHP\r\n$headers";
  else
    $headers="X-mailer: CompInaBox via PHP";
  for ($i = 0; $i < $numAddresses; $i++)
    {
      if ($i % 25 == 24)
	{
	  mail($to,$subject,$body,
	       "From: $from\r\nbcc:$bcc\r\n$headers");
	  $bcc="";
	}
      $bcc .= ($bcc=="" ? "" :", ") . $addresses[$i];
    }
  if ($bcc!="")
    mail($to,$subject,$body,
	 "From: $from\r\nbcc: $bcc\r\n$headers");
}
Breaking up each mailing into batches of 25 tends to make host providers happier as it lessens the load of any one process and gives the scheduler an easier swap job.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I just looped the mail function so it sends e-mail to everyone.

->nielsene

That's a pretty cool script, do you have the actual script by SourceForge?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

The actual SourceForge script can be found at multiple places on SourceForge.net and other places. Here's a link to the last open source version of that file.

Really long URL, which would break the forum
Last edited by nielsene on Tue Jun 03, 2003 9:06 am, edited 1 time in total.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Thanks :D
owen
Forum Newbie
Posts: 15
Joined: Fri May 30, 2003 12:40 pm

nielsene

Post by owen »

nielsene since we're on the topic of email - what about batching the emails and then sending them out? For example you have a forum. would it be best batch the emails and then check for spam before sending them out. Or send them out instantly and have fload control?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Well the method I posted does the mass mailing in mini batches. But I think you are talking about batching multiple different emails? In which case I beleive that ceases to be a PHP issue and is something that your local mail server handles automatically. I know EXIM on my local server handles the "flood control" aspect.

And as very few people have permission to send email via my page I don't worry about spam. I'm one of three providers of the service I provide and people play by my rules rather than use the option of using it....
Post Reply