I want to send the following fields to wp_mail
If i put all the emails in Email to
,Copy to
and Bcc to
in an array $emails
and pass it to wp_mail. How do i set the headers for cc and bcc in wp_mail?
$headers = 'From: Test <[email protected]>' . '\r\n';
$headers.= 'Content-type: text/html\r\n';
$success = wp_mail( $emails, $subject, $message, $headers );
= "CC: [email protected]\r\n"; $recipient . = "BCC: [email protected]\r\n"; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" .
wp_mail() is a PHPMailer function that generates and sends your WordPress emails. By default, almost all WordPress plugins use wp_mail() to send emails. But the wp_mail() function is not very reliable. So when something goes wrong with it, you'll find email delivery issues across your whole site.
Just like the physical carbon copy above, CC is an easy way to send copies of an email to other people. If you've ever received a CCed email, you've probably noticed that it will be addressed to you and a list of other people who have also been CCed.
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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With