2011-10-10 99 views
0

我正在使用此脚本向用户朋友发送通知。问题是所有recepieints看看谁还有这个电子邮件。我如何调整代码,使电子邮件仍然发送给所有人,但他们看不到还有谁收到了它?如何防止receipeints看到哪些其他电子邮件地址收到了电子邮件?

代码:

$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 ""; 

回答

1

使用additional_headers字段添加BCC *地址。见the manual

从手册页:

// 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); 

的 “birthdaycheck” 电子邮件是隐藏的。

*(密件抄送)

在你的脚本它会成为这样的:

$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 ""; 
+0

我该如何使它适合我的脚本。我无法得到它的工作ifi我使用密件抄送:在$电子邮件前面.. – AAA

+1

修复你自己的代码示例 – Nanne

+0

谢谢!它部分工作。第一个收件人看不到还有谁收到了。但第二个收件人能够看到还有谁发送了该电子邮件。 – AAA

1

将消息发送实际的循环。这样你就可以将电子邮件单独发送给每个收件人,而不是一次发送。

相关问题