开发者

email users using array from foreach

开发者 https://www.devze.com 2023-03-26 18:47 出处:网络
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 use

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.

开发者_StackOverflow社区$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

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消