How do I validate an array of emails from a textbox before sending them to the wp_mail() function?
$emails = '[email protected];[email protected]
[email protected],[email protected], email5.com';
$emails = preg_split('/[;,\n]/', $emails);
$validEmails = array();
$subject = 'Hey Subject';
$message = 'I am a message';
foreach($emails as $key=>$value){
if (is_email($value)) {
array_push($validEmails, $value);
}
}
wp_mail($validEmails, $subject, $message, $headers);
The sample code above stops on the if (is_email()) condition. How can I validate each email in the array whichever way before sending to the mail function?