0

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("noreply@test.com", $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

  • 2
    `BUT i dont know how to replace them for each user without putting wp_mail function inside the foreach loop`...there isn't. If you want different content to go to each user, then you have to send a separate email to each user. That is simple logic. If your server can't handle that, consider integrating with a 3rd party bulk-mailing service – ADyson Jun 27 '23 at 15:11

1 Answers1

0

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

Alessandro
  • 125
  • 1
  • 11