AAA
AAA

Reputation: 3168

How to prevent receipeints from seeing which other email addresses have received an email?

I am using this script to send notificaitons to users friends. the problem is that all recepieints get to see who else got this email. How do i tweak the code so the emails still get sent to all but they can't see who else got it?

Code:

    $sql = "SELECT STRAIGHT_JOIN DISTINCT email from
    friend_email_ids WHERE my_id='$id'";
    $result = mysql_query($sql);

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

    if ($result == "")
    {
    echo "";
    }
     echo "";


   $rows = mysql_num_rows($result);
   $emails = array(); 

   if($rows == 0)
   {
   print("");

    }
   elseif($rows > 0)
   {
    while($row = mysql_fetch_array($query))
        array_push($emails, $row['email']);

   {

   $email = $row['email'];


  print("");
  }

  }

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";
$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";
mail(implode(",", $emails), "Subject: $subject",
$message, "$headers" );
echo "";

Upvotes: 0

Views: 128

Answers (4)

Nanne
Nanne

Reputation: 64399

Use the additional_headers fields to add a BCC* address . See the manual

From the manual page:

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

the "birthdaycheck" email is hidden.

*(Blind Carbon Copy)

In you script it would become something like this:

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";

////////////pay attention here
$headers .= "BCC: ".implode(",", $emails)."\r\n";
$to = "[email protected]"; //the mail in the "TO", visible to all. there has to be 1.
////////////////////////

$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";

mail($to, "Subject: $subject",
$message, "$headers" );
echo "";

Upvotes: 1

Ryan
Ryan

Reputation: 3171

From PHP.net you'll find that the Bcc feature of mail() is what you need to use.

Like zoy (for multiple peeps):

$headers .= 'Bcc: [email protected],[email protected],[email protected],[email protected],' . "\r\n";

Happy Haxin!

_wryteowl

Upvotes: 1

Roy
Roy

Reputation: 117

Put the actual sending of messages in the loop. That way you will send the e-mail to each recipient individually instead of all at once.

Upvotes: 1

Tobias
Tobias

Reputation: 9380

Just use BBC for all recipients:

Bcc: recipients get a copy of the email, but their email address is automatically deleted at delivery. Nobody except you and the Bcc: recipient will know that they got a copy, and their email address will not be exposed.

-> http://email.about.com/od/emailmanagementtips/qt/How_to_Send_an_Email_to_Undisclosed_Recipients.htm

Upvotes: 2

Related Questions