I asked a previous question about this but it has changed since, I would like to create an array from the db query '$to' and use it in the email_to_user() function. This will hopefully email all users from the $entry->dept array.
When $entry->dept = 1 this works and emails the user from department #1
when $entry->dept = 1,30 the email function fails.
$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 {}
?>
Sending mails with PHP