私はフロントエンドフォームを持っており、特定のユーザロール内のすべてのユーザに電子メールを送信します。それは問題なく送信されますが、電子メール自体の中では、最後のユーザーの名前(ユーザー役割内のユーザーの一覧から)、すべての受信者の電子メールが印刷されます。ワードプレスでwp_mail()に各ユーザ名を追加
誤って設定した配列や変数とは関係があります。どのユーザーがどのように電子メールを受信し、正しい名前がそれらのために印刷されるかについて、どんな助けも評価されるでしょう!ここで
は私のコードです:
// Get users and their roles.
$user_args = array(
'role__in' => 'test_role',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users($user_args);
$user_name_list = array();
foreach ($users as $user) :
$user_email_list[] = $user->user_email;
$user_name_list[] = $user->display_name;
endforeach;
$user_name = $user_name_list;
// This is part of the code that adds their username to the email content.
$body = '<p style="margin-bottom: 20px;">Hello ' . $user_name . ',</p>';
回答:http://stackoverflow.com/questions/43833428/using-a-variable-outside-php-foreach-loop –