PHP邮件BCC多个收件人

22

我该如何发送一个密件抄送邮件? 如果我发送该邮件,它会显示所有的收件人!

$to=array();
$members_query = mysql_query("select email from members");
while( $row = mysql_fetch_array($members_query) )
{
    array_push($to, $row['email']);
}

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

// Additional headers
//$headers .= 'To: '.$newName.' <'.$newEmail.'>' . "\r\n";
$headers .= 'From: SmsGratisan.com <admin@website.com' . "\r\n";


mail(implode(',', $to), $title, $content, $headers);

谢谢!


您需要添加一个BCC(密送)头部,其中包含收件人列表。请参考手册中的示例。 - Jonnix
4个回答

34
将您的电子邮件字段设置为null,然后在标头中将$to数组合并。
$headers .= 'From: SmsGratisan.com <admin@website.com>' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


mail(null, $title, $content, $headers);

1
很好的回答,我认为你漏掉了一个“>”。 - Chimdi

0
$headers .= 'Bcc: mail@example.com' . "\r\n";

-2

-3
请使用 pass Just Array 代替做任何种类的Implode、设置引号、逗号等。
示例:
    $bcc = array();

    foreach ($users as $user) 
    {
        $bcc[] = $user['User']['email'];
    }   

并将此传递给Mail函数:

        $email->from($from)
//            ->to($from)
              ->bcc($bcc)

谢谢, Ankit Patel


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接