wp_mail function to send massive emails - problem with placeholders

54 Views Asked by At

So far sending massive emails its fine using Bcc

foreach ($users as $key => $user) {
  if ($user->roles[0] != "administrator") {

     $headers[] = 'Bcc: ' . $user->user_email;
  }

}
                            
wp_mail("[email protected]", $subject, $message, $headers);

The problem is that emails have variables, like Hello, {{user_name}} BUT i dont know how to replace them for each user without putting wp_mail function inside the foreach loop, since Bcc its the best approach

Currently the way I am replacing the variables when sending emails to single users, its this way

$message = str_replace(
         ['{{user_name}}'],
         [$user->user_login],
         $message
         );

so what i am asking its a way of replacing the variables specially when its massive emails

1

There are 1 best solutions below

0
Alessandro On

You simply can't send emails with different content without looping.