PHP Sending bulk emails: one for each or all?

When sending bulk emails using PHP, is it better to send an email to each subscriber (the for loop runs through all email addresses), or is it better to just add everything to the BCC in a comma-separated list, and thus send only one email?

Thank.

+5
source share
4 answers

There is a good chance that the number of addresses in the BCC field is limited on the SMTP server (to avoid spam). I would go with a safe route and send an email to each individual subscriber. It will also allow you to set up email for each subscriber, if necessary.

, mail(), , (- , SMTP-). PEAR:: Mail.

+4

.

linux, , , !

-, - , chancks . , , :)

+1

- (, ) BCC, ( 99% ).

PHP, , .

+1

As others say, one mail is better for each recipient.

If you want the library to do the dirty work for you, try SwiftMailer http://swiftmailer.org

Here is an example directly from the docs:

require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$numSent = $mailer->batchSend($message);

printf("Sent %d messages\n", $numSent);

/* Note that often that only the boolean equivalent of the
   return value is of concern (zero indicates FALSE)

if ($mailer->batchSend($message))
{
  echo "Sent\n";
}
else
{
  echo "Failed\n";
}

*/

It also has a beautiful Antiflood plugin: http://swiftmailer.org/docs/antiflood-plugin-howto

+1
source

All Articles