我之前问了一个关于此的问题,但它已经改变了,因为我想从db查询'$to'
创建一个数组,并在email_to_user()
函数中使用它。希望能够通过$entry->dept
阵列向所有用户发送电子邮件。
当$entry->dept = 1
有效时,会通过department #1
向用户发送电子邮件
当$entry->dept = 1,30
电子邮件功能失败时。
$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)
function email_to_user($toemail, $from, $subject, $body){
$headers = "From: $from\r\n" .
"Reply-To: $from\r\n" .
"X-Mailer: PHP/" . phpversion();
$result = true;
foreach ($toemail as $email){
if (!mail($email, $subject, $body, $headers)){
$result=false;
break;
}
}
return $result;
}