在WordPress中向wp_mail()添加电子邮件列表

时间:2017-04-26 09:53:27

标签: wordpress email

我正在尝试从某个用户角色向wp_mail()添加电子邮件地址列表。我有一个以逗号分隔的列表存储为$user_email_list但无法将其输出到$multiple_recipients数组中。

非常感谢任何帮助。

// 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;

1 个答案:

答案 0 :(得分:1)

更新你的foreach代码,并在最后检查你的$ multiple_recipients变量,它将是逗号分隔值。

foreach ( $users as $user ) :
  $user_email_list[] = $user->user_email;
endforeach;

$multiple_recipients = implode(', ', $user_email_list);