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.
Related Posts:
- WordPress refuses to send mail, “…your host may have disabled the mail() function”
- WordPress “phpmailer_init” not working for me
- How do I override the Message-ID header of wp_mail function?
- WordPress new user / forgot password emails are broken
- wp_mail function timing out
- Why is my get_post_meta always empty
- Should I use wp_mail or PHP’s mail? [duplicate]
- Mail not sent when I set HTML headers
- Error when requesting password reset email – wp authentication
- Processing a subscription form with POST method?
- Different Webhost and using Google Mail server: Is there a better way than SMTP?
- wp_mail not sending
- Redirect to another page after submission using wp_mail
- PHP 8, AJAX mail form to function.php doesn’t work
- How to retrieve the sender email with wp_mail()?
- wp_mail file attachment not being placed in upload folder?
- Website needs to be opened for wp_mail to work
- Notify users only on post publish
- Sending a custom form data in email through WP Mail Function
- Pass Variables or Variable Place-Holder from Editor to PHP
- Pass return-path additional parameter in wp_mail
- Send notification email to admin for every new post published
- Different SMTP based on domain
- Get page permalink in contact form
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Running SMTP Conditionally
- Including user data in “new user notification email”
- Cron not sending wp-mail()
- Email always ends up in spam
- Premature end of script headers: wp-mail.php?
- Adding action item to admin users table and sending email
- Wp_mail doesnt work
- get_post_meta is always empty when I use wp_mail
- How to show value from ACF plugin field in e-mail?
- wp_mail vs mail functions and header arrays
- Word press – JSPDF – Sending PDF as attachment from wp_mail – Special characters
- wp_mail – send emails after 24 hours from users registration
- Send emails to individual subscribers when CPT post is deleted (trashed)
- Send registration email to all admins
- Why isn’t WordPress part of Framework Interop Group?
- Is there a way to use the WordPress users but without loading the entire WordPress core?
- Custom HTML structure in wp_list_categories
- How to protect own PHP code from WordPress updates
- get_template_part not working with ajax
- Javascript code inside “” in core WordPress files .php
- Placing the_content inside shortcode not working
- Exclude posts from homepage having a specified tag
- PHP in post content [closed]
- PHP Script for last login time
- Is there a WordPress version that is incompatible with PHP 5.3?
- Implement One Time URL Script
- Unable to write multiple values back to ACF user field – PHP
- PHP Array Returning [object Object]. Tried existing answers results with no luck
- Why Won’t My Inputs in a form with a Get method work together?
- Extend PHP regex to cover “srcset” and “style” attributes
- Value prints outside of the echo
- If ‘editor’ is empty, then
- Different Subdomain changes page content
- Removing the comment function within wordpress
- Does get_post function counts as view?
- Get ACF options field in PHP acting as CSS
- Permalinks are not working in WordPress in digitalocean
- Bootstrap Carousel HTML structure and funny output [closed]
- add category to posts with tag wordpress
- Missing a text-domain esc_attr_e
- Get all posts from categories
- How to add post classes?
- How to Generate a list of Most Commented post?
- Updating From Mobile App – Exposing Site to Hacking
- Extract and display user infromation on an automatically created page
- Using multiple variables to assign categories to an array
- Show Custom Menu Name in WordPress 3
- Execute PHP code only with specific user role
- Repeat a function with 24hrs gap for n number of days
- Add a custom WooCommerce settings tab with sections
- How to serve WordPress folder over subdomain?
- How to call my PHP function with AJAX ? wp_query
- Show sidebar only to author of post
- No more get_option(‘date_time’) in WordPress 5.5?
- How to update post content of all posts with tag?
- Make WooCommerce product categories only show images on homepage
- How to Change Site Elements based on referring URL
- WP post meta – for loop inside for loop
- Prepared DB Query from _POST array
- WordPress using get_term to retreive slug not working as expected
- auto metakey value on post tile
- Static home page ignored
- How to pass parameter that ends up being part of a class name with wordpress shortcode
- calling a function from a class in your template
- Custom single.php files for different post formats
- Troubleshooting “loopback requests that take too long”
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- If I define a variable in header.php, how do I make it available to templates?
- Order woo products, but first products must be with acf fields
- Remove /category/ from category (archive) page URLs (without using a plugin)
- JSON Object Value Show Undefine
- Redirect loop upon installation of my plugin
- WordPress wp_remote_request() – How to do async await in wordpress php?
- WordPress blog header error
- Advanced Custom Fields Auto Populating Field Values For Nested Repeater FIelds