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 . ', ';

// Email Data
    $multiple_recipients = array(
    $subject = $post->post_title;
    $body    = $post->post_content;

Read more here: Adding a list of emails to wp_mail() in WordPress


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: