22

How do I make a bcc mail? If I send that mail, It shows me all the recipients!

$to=array();
$members_query = mysql_query("select email from members");
while( $row = mysql_fetch_array($members_query) )
{
    array_push($to, $row['email']);
}

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

// Additional headers
//$headers .= 'To: '.$newName.' <'.$newEmail.'>' . "\r\n";
$headers .= 'From: SmsGratisan.com <admin@website.com' . "\r\n";


mail(implode(',', $to), $title, $content, $headers);

Thanks!

Teknikk
  • 251
  • 1
  • 8
  • 22
user1936192
  • 335
  • 2
  • 4
  • 10
  • You need to add a BCC header with list of recipients. See [the manual](http://php.net/manual/en/function.mail.php) for examples. – Jonnix Jan 09 '13 at 15:08

4 Answers4

34

Set your mail to field to null, and then implode your $to array in your headers

$headers .= 'From: SmsGratisan.com <admin@website.com>' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


mail(null, $title, $content, $headers);
Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
0
$headers .= 'Bcc: mail@example.com' . "\r\n";
FlourishDNA
  • 500
  • 1
  • 8
  • 20
-2

CC and BCC can be sent as headers (see: http://php.net/manual/en/function.mail.php).

You can also use other mail libraries - the PEAR Mail library makes sending emails a little more object-oriented. http://pear.php.net/package/Mail/redirected

dethtron5000
  • 10,363
  • 1
  • 31
  • 32
-3

Please use pass Just Array instead of doing any kind of Implode, Set quotes, comma etc.

Example:

    $bcc = array();

    foreach ($users as $user) 
    {
        $bcc[] = $user['User']['email'];
    }   

And pass This To Mail Function:

        $email->from($from)
//            ->to($from)
              ->bcc($bcc)

Thanks, Ankit Patel

pinckerman
  • 4,115
  • 6
  • 33
  • 42