Any help would be appreciated.
$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 {
} ?>
Works great when emailing one person but when you try to email a few in the array it does not work.
It’s because you send the email outside the loop and above that, overwrite the data with each iteration of the loop.
What you probably are attempting to do: