$sql = "select emailid from table where category = 1";
while($row=mysql_fetch_array($sql))
{
$email=$row['emailid'];
$to = $email;
$subject = "E-mail subject";
$body = "E-mail body";
$headers = 'From: info@mydomain.com' . "\r\n" ;
$headers .= 'Reply-To: info@mydomain.com' . "\r\n";
mail($to, $subject, $body, $headers);
}
假设上面的代码将从数据库中获取100个电子邮件ID,并将邮件逐个发送到每个电子邮件ID。但我想要做的是....获取数组中的所有电子邮件ID,并立即将它们作为“BCC”发送到每封电子邮件。还有一件事我想为每个id定制电子邮件正文内容....
有什么想法吗?
答案 0 :(得分:1)
你想做什么是不可能的。如果您通过To / CC / BCC中的多个地址立即发送它们,则每个人都会收到完全相同的电子邮件。所以你无法定制身体。
如果向所有人发送相同的电子邮件是正常的,请尝试以下方法:
$sql = mysql_query("select emailid from table where category = 1");
$recipients = array();
while($row = mysql_fetch_array($sql)) {
$recipients[] = $row['emailid'];
}
$to = 'info@mydomain.com';
$subject = "E-mail subject";
$body = "E-mail body";
$headers = 'From: info@mydomain.com' . "\r\n" ;
$headers .= 'Reply-To: info@mydomain.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
mail($to, $subject, $body, $headers);