Are you aware you can pass a comma-separated string of email adresses to wp_mail
?
// Make sure your email strings only uses comma as a separator
$emails = preg_replace('~[,;\s]+~', ',', $emails);
Then just throw that string into wp_mail
’s first argument. Depending on exactly what you want to do with the emails, this approach may be sufficient.
The wp_mail
function internally relies on the PHPMailer library (unless you use a redefined wp_mail
function). PHPMailer validates the email before adding it to the recipient list. Invalid emails will be skipped.