在WordPress中添加一个电子邮件列表到wp_mail() [英] Adding a list of emails to wp_mail() in WordPress
本文介绍了在WordPress中添加一个电子邮件列表到wp_mail()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从某个用户角色向wp_mail()添加一个电子邮件地址列表。我有一个逗号分隔列表存储为 $ user_email_list
,但无法将其输出到 $ multiple_recipients
数组中。
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.
任何帮助将不胜感激。
// 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;
推荐答案
更新foreach的代码,并检查$ multiple_recipients变量在最后,它将是逗号分隔的值。
Update your code of foreach and check your $multiple_recipients variable at final, it would be comma separated value.
foreach ( $users as $user ) :
$user_email_list[] = $user->user_email;
endforeach;
$multiple_recipients = implode(', ', $user_email_list);
这篇关于在WordPress中添加一个电子邮件列表到wp_mail()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文