任何帮助都将不胜感激。
$divisions = explode(",", $entry->dept);
foreach($divisions as $division) {
$divs=get_record('induction_emails','id',$division);
$useremail = get_record('user', 'email', $divs->email);
$to = get_record('user', 'id', $useremail->id); }
if (email_to_user($to, $from, $subject, $body)){
redirect('thanks.php'); die;
} else {
} ?>
通过电子邮件发送给一个人时效果很好,但是当您尝试通过电子邮件发送数组中的一些时,它无效。
答案 0 :(得分:2)
这是因为您在循环之外和之上发送电子邮件,在循环的每次迭代时覆盖数据。
您可能正在尝试做什么:
<?php
$statuses = array();
$divisions = explode(",", $entry->dept);
foreach($divisions as $division) {
$divs=get_record('induction_emails','id',$division);
$useremail = get_record('user', 'email', $divs->email);
$to = get_record('user', 'id', $useremail->id);
$email_status = email_to_user($to, $from, $subject, $body);
$statuses [] = array('email_to' => $to, 'success' => $email_status);
}
foreach($statuses as $status) {
if(!$status['success']) {
//something went wrong with this email, handle it
}
}
redirect('thanks.php'); die;
?>
答案 1 :(得分:0)
如果您想在列表中发送电子邮件,请尝试以下操作:
foreach($divisions as $division)
{
$divs=get_record('induction_emails','id',$division);
$useremail = get_record('user', 'email', $divs->email);
$to = get_record('user', 'id', $useremail->id);
email_to_user($to, $from, $subject, $body);
}
也许你想让它变得高效并且BCC整个列表?创建一个新功能来发送带有BCC的电子邮件,而不是TO。提供所有收件人的逗号/分号值字符串。
foreach($divisions as $division)
{
$divs=get_record('induction_emails','id',$division);
$useremail = get_record('user', 'email', $divs->email);
$bcc .= get_record('user', 'id', $useremail->id).";";
}
send_email_bcc($bcc, $from, $subject, $body);
要在循环中连接字符串,请使用.=
运算符:
$myVariable .= get_record('user', 'id', $useremail->id).";";
我在上面的每个电子邮件地址末尾都包含一个分号作为分隔符。