Solving the PHPMailer BCC list problem

How to add a BCC list using the PHPMailer class

It's much faster, if you are sending out a lot of emails, to send the email to one person (yourself, perhaps) and blind copy it to everyone else.

 

Some people seem to struggle with getting the PHPMailer class to add a BCC list but it is actually very simple:

 

Let's assume that you have your list of BCC recipients in an array. In this example, they are in the array $list

Simply loop through the array and call the PHPMailer function AddBCC():

 

foreach($list as $bccer){

   $mail->AddBCC($bccer);

}

 

And that's it. Simple, eh?

 

Creating a BCC list as an array

Simply use PHP's array() function:

 

$list=array('angela@example.com','bob@somedomain.com','nobody@example.com');

 

Creating a BCC list as an array from a database

This is also straight-forward and there are a few ways of extracting data into an array but I think this one is the easiest to follow:

 

$sql="select emailaddress from emaillist";

$result = mysql_query($sql) or die("Invalid query: " . mysql_error());

$result = mysql_query($sql) or die("Invalid query: " . mysql_error());

 

$num=mysql_numrows($result);

$y=0;

 

array($list);

while($y < $num){

   $list[$y]=mysql_result($result,$y,"emailaddress");

   $y++;
			

}