PHP Mail通过多个函数调用隐藏其他收件人地址


PHP Mail hide other recipient addresses with multiple function calls

我有一个PHP脚本,它在函数调用中向多个收件人发送电子贺卡(将逗号分隔的电子邮件地址和mail()数组分别发送给每个收件人)。然而,当查看收到的电子邮件时,每个客户端都可以看到电子邮件发送到的其他地址,这使我相信它们都是在一个电子邮件中发送的,尽管有单独的mail()调用。下面是我当前的代码:

<?php
$headers  = "From: ".$_POST['email']."'r'n"; 
$headers .= "Content-type: text/html'r'n";
$array=explode(",", $_POST['sendto']);
for ($i = 0; $i < count($array); ++$i) {
    mail(trim($array[$i]), "Happy Holidays!", $body, $headers);
}
?>

如何解决这个问题,以便收件人只能在"to"字段中看到他们的电子邮件地址?谢谢!

您要使用的是BCC字段。

  • https://en.wikipedia.org/wiki/Blind_carbon_copy
代码:

<?php
$_POST['email'] = str_replace(array("'n", "'r"), '', $_POST['email']);
$_POST['sendto'] = str_replace(array("'n", "'r"), '', $_POST['sendto']);
$headers = "From: " . $_POST['email'] . "'r'n"
         . "Content-Type: text/html'r'n"
         . "BCC: " . $_POST['sendto'] . "'r'n";
mail($_POST['email'], 'Happy Holidays!', $body, $headers);
?>

将电子邮件发送给发件人,但密件抄送给收件人。此外,我从BCC和from字段中删除了'r和'n字符,否则将允许邮件头注入攻击。