不带任何扩展名的php only mail()函数

不带任何扩展名的php only mail()函数,php,email,Php,Email,我试图在发送电子邮件时不透露收件人,但我未能做到: $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-Mai

我试图在发送电子邮件时不透露收件人,但我未能做到:

$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);
$email=内爆(“;”,$email);//我在哪里有电子邮件
$to=$email;//webmaster@domain.com; webmaster@anotherdomain.com
$subject='subject';
$headers=“From:noreply@domainfromwhereisendemail.com\r\n”。“X-Mailer:php\r\n”;
$headers.=“MIME版本:1.0\r\n”;
$headers.=“内容类型:text/html;字符集=ISO-8859-1\r\n”;
$headers.=“收件人:未公开的收件人\r\n”;
//$headers.=“抄送:$to\r\n”;
$message=

除非您使用循环单独发送电子邮件,否则您无法阻止不披露

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

$email=内爆(“;”,$email);// 下面是一个调用
mail()
解决方案:

$subject='subject';
$headers=“X-Mailer:php\r\n”;
#$headers.=“MIME版本:1.0\r\n”;#你真的需要吗?
$headers.=“内容类型:text/html;字符集=ISO-8859-1\r\n”;
foreach($email作为$mail){
$headers.=“密件抄送:”.$mail.\r\n”;
}
$message=

哦,你能给我一个基于我的例子吗?非常感谢。它正在工作,我还需要//注释$headers.=“收件人:未披露的收件人。。。一旦stackoverflow允许,将标记为已接受。那么,您应该从标题中删除To:部分。虽然这种方法通常是可行的,但可能会有问题,因为它会一个接一个地发送电子邮件——脚本最终会超时。设置From:标题总是一个糟糕的主意-不要这样做。请看ôkio的评论,然后再看。@blue-hmm不想超时,我正在努力理解,你到底是如何像okio说的那样发送电子邮件的,我需要添加密件抄送而不是我的抄送行吗?@user3467855,两者都是相同的,即使你可以使用上述推荐的方法,因为在这两种情况下,您都会将邮件分别发送给每个收件人。您可以将邮件发送给自己或普通电子邮件,当有150封电子邮件时,如果您希望为前10位用户发送电子邮件,则为每个收件人添加密件抄送,您将如何更改此逻辑?@ShankarDamodaran-这是一个完全不同的问题,通过预先过滤$email数组中的值可以非常容易地解决。干杯。也许是对的,但是当你使用密件抄送功能时,收件人可以很容易地发现邮件不是专门为他/她发送的,而是发送给一个组(但是,其他收件人的电子邮件不会被披露)。如果OP不关心这个问题,那么这是正确的做法。
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);
}
$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);