我正在尝试使用PHP向多个收件人发送电子邮件。我的代码就像这样
<?php
foreach($subscribers as $subscriber){
$email[] = $subscriber['email'];
}
$emails = implode(',', $email);
$email_from = "email@example.com";
$subject = "My Subject";
$full_name = 'Example Sender';
$from_mail = $full_name.'<'.$email_from.'>';
$email_text = file_get_contents('email.html');
$headers .= 'From: ' . $from_mail . "\r\n".
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";
mail($emails, $subject, $email_text, $headers);
?>
我可以正确发送电子邮件。但是它显示了电子邮箱中的其他电子邮件地址,我不想彼此共享电子邮件地址。请帮忙我该怎么做。我尝试在每个循环中发送电子邮件,如此
<?php
foreach($subscribers as $subscriber){
$email = $subscriber['email'];
$email_from = "email@example.com";
$subject = "My Subject";
$full_name = 'Example Sender';
$from_mail = $full_name.'<'.$email_from.'>';
$email_text = file_get_contents('email.html');
$headers .= 'From: ' . $from_mail . "\r\n".
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=UTF-8" . "\r\n";
mail($email, $subject, $email_text, $headers);
}
?>
但它仅向循环内的第一个电子邮件地址发送电子邮件。请帮忙。
答案 0 :(得分:0)
您可以在$email
字段中添加空字符串,并使用密件抄送标头添加邮件地址。密件抄送确保接收方无法看到其他电子邮件地址。
$headers .= "Bcc:email@example.com" . PHP_EOL;