我正在使用此脚本向用户朋友发送通知。问题是,所有接收者都会看到还有谁收到这封电子邮件。我如何调整代码,以便电子邮件仍然发送给所有人,但他们看不到谁还有它?
代码:
$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 "";
答案 0 :(得分:2)
只需对所有收件人使用BBC
:
密送:收件人会收到电子邮件的副本,但他们的电子邮件地址是 在交货时自动删除。除了你和Bcc之外没有人: 收件人会知道他们有副本,他们的电子邮件地址会 不要暴露。
- &GT; http://email.about.com/od/emailmanagementtips/qt/How_to_Send_an_Email_to_Undisclosed_Recipients.htm
答案 1 :(得分:1)
使用additional_headers
字段添加BCC
*地址。见the manual
从手册页:
// 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);
隐藏“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 = "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 "";
答案 2 :(得分:1)
在循环中实际发送消息。这样,您就可以单独向每个收件人发送电子邮件,而不是一次性发送。
答案 3 :(得分:1)
从PHP.net您会发现mail()的密件抄送功能是您需要使用的功能。
喜欢zoy(多次偷窥):
$headers .= 'Bcc: someone@example.com,someone2@example.com,someone3@example.com,someone4@example.com,' . "\r\n";
哈欣快乐!
_wryteowl