未公开收件人 php 没有任何扩展名,只有 mail() 函数


Undisclose recipients php without any extensions only mail() function

我试图在发送电子邮件时不透露收件人,但我失败了:

$email = implode('; ', $email); // array where I have the emails
$to = $email; // webmaster@domain.com; webmaster@anotherdomain.com
$subject = 'Subject';
$headers  = "From: noreply@domainfromwhereisendemail.com'r'n" . "X-Mailer: php'r'n";
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";
$headers .= "To: Undisclosed Recipients <noreply@domainfromwhereisendemail.com>'r'n";
//$headers .= "Cc: $to'r'n";
$message = 
<<<START
This is the message
START;
mail($to, $subject, $message, $headers);

我尝试添加抄送或密件抄送,但不起作用,它除了添加电子邮件外,还添加了未公开的收件人。我正在尝试在没有任何其他扩展的情况下执行此操作,我在这里检查了很多来自stackoverflow的问题,但没有完成此操作。电子邮件仍在向每个人显示。

,您无法阻止其保密,除非您使用循环单独发送电子邮件。

$email = implode('; ', $email); // <---- Don't do this.

循环方式..

foreach($email as $mail)   #<---- Use a foreach and loop through
{
$to = $mail;
$subject = 'Subject';
$headers  = "From: noreply@domainfromwhereisendemail.com'r'n" . "X-Mailer: php'r'n";
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";
$message =
    <<<START
    This is the message
START;
mail($to, $subject, $message, $headers);
}
这是只需

调用一次mail()即可的 ôkio 解决方案:

$subject = 'Subject';
$headers = "X-Mailer: php'r'n";
# $headers .= "MIME-Version: 1.0'r'n"; # do you really need that?
$headers .= "Content-Type: text/html; charset=ISO-8859-1'r'n";
foreach($email as $mail){
    $headers .= "Bcc: ".$mail."'r'n";
}
$message =
    <<<START
    This is the message
START;
mail('non@existing.email', $subject, $message, $headers);