Click to See Complete Forum and Search --> : mail() function and Bcc field


Alhazred
April 16th, 2009, 02:40 PM
I need to send the same email in plain text format to several users.
I can do that, but there is a problem: those users who use a gmail account (and only them) can see the email addresses in the Bcc field.

Is there a way to hide those addresses to gmail users?

This is my code

$i=0;
while($row = mysql_fetch_array($addresses)) {
if($i==0) //first addres into the field To:
$receiver = $row['email'];
else //others into Bcc
$bcc .= $row['email'].", ";
$i++;
}

$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text; charset=iso-8859-1\r\n";
$header .= "From: My site <email@mysite.com> \r\n";
$header .= "Bcc: ".$bcc."\r\n";
$object = "email's object";
$message = "email's text.\r\n";
mail($receiver, $object, $message, $header);

PeejAvery
April 16th, 2009, 03:21 PM
I altered you script a tiny bit (acquiring e-mail addresses). None of my Gmail accounts saw any other BCC headers. However, I did make one other change. I added a declaration of the variable instance $bcc. You have not declared it anywhere. So, when you are appending to it, it doesn't exists the first time. Same happens with $header.

$bcc = '';
$i = 0;
while($row = mysql_fetch_array($addresses)) {
if ($i == 0) {$receiver = $row['email'];}
else {$bcc .= $row['email'].", ";}
$i++;
}

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text; charset=iso-8859-1\r\n";
$headers .= "From: My site <email@mysite.com> \r\n";
$headers .= "Bcc: ".$bcc."\r\n";
$subject = "email's subject";
$message = "email's text.\r\n";
mail($receiver, $subject, $message, $headers);