Adding a list of emails to wp_mail() in WordPress

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;

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

Leave a Reply

Your email address will not be published. Required fields are marked *