You can use an array to send all the info you need, thus:
$headers[] = 'From: Test <[email protected]>';
$headers[] = 'Cc: [email protected]';
$headers[] = 'Cc: [email protected]';
...
$headers[] = 'Bcc: [email protected]';
$headers[] = 'Bcc: [email protected]';
$success = wp_mail( $emails, $subject, $message, $headers );
You can get it programmatically, being $copy_to
and $bcc_to
arrays of said form fields after splitting them by the comma you state in the inner field text, and having defined array $headers
:
$headers[] = 'From: Test <[email protected]>';
foreach($copy_to as $email){
$headers[] = 'Cc: '.$email;
}
foreach($bcc_to as $email){
$headers[] = 'Bcc: '.$email;
}
$success = wp_mail( $emails, $subject, $message, $headers );
These work because wp_mail()
doesn't trust you, so normalizes and concatenates multiple Cc:
and Bcc:
headers correctly. The RFC spec mandates that these headers occur only once, with multiple recipients comma-separated, and "folded" if the lines are too long, so it wouldn't work in plain PHP.
$emails
$emails
is simply an array of email address. I don't know how to set headers cc and bcc for the emails in the array.