开发者

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开发者_StackOverflow社区($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 "";


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


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

From the manual page:

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\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 = "youremail@domain.com"; //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 "";


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.


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: someone@example.com,someone2@example.com,someone3@example.com,someone4@example.com,' . "\r\n";

Happy Haxin!

_wryteowl

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜