【发布时间】:2015-07-23 06:49:23
【问题描述】:
我正在尝试使用 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);
?>
我能够正确发送电子邮件。但它会在邮箱中显示其他电子邮件地址,我不想彼此共享电子邮件地址。请帮助我该怎么做。我尝试像这样在 for each 循环中发送电子邮件
<?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);
}
?>
但它只向循环内的第一个电子邮件地址发送电子邮件。请帮忙。
【问题讨论】: