I am trying to add a list of email addresses to wp_mail() from a certain user role. I have a comma delimited list stored as $user_email_list
but cannot get that to output into the $multiple_recipients
array.
Any help would be greatly appreciated.
// Get users and their roles, create list of emails to send notification to.
$user_args = array(
'role__in' => 'test_role',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users($user_args);
foreach ( $users as $user ) :
$user_email_list = $user->user_email . ', ';
endforeach;
// Email Data
$multiple_recipients = array(
$user_email_list
);
$subject = $post->post_title;
$body = $post->post_content;
Update your code of foreach and check your $multiple_recipients variable at final, it would be comma separated value.