Bcc in WordPress Mail

I was constantly getting the queries regarding how to add multiple recipients to a WordPress mail. So here I have tried to give a simple but elegant solution to Cc, Bcc in WordPress mail.

Email is one of the instant tools for business communication. It can be sent to multiple people for collaboration. Messages move quickly and lots of information can be shared in the body of the email. An email provides you different fields to add the recipients with the distinct motives. For example To, Cc, Bcc.

  • To is for Intended Actionable Recipients.
  • Cc (Carbon Copy) is for people you want should know about the message without any direct involvement. Added only to keep informed. The receiver comes to know about all the persons who are receiving email through Cc.
  • Bcc (Blind Carbon Copy) is used when you want to send an email to others but without knowledge of other recipients.

In the case of WordPress too, you need to send the same email to multiple recipients. All the available plugins to Cc, Bcc in WordPress mail are now obsolete. So, you can simply use the following code to add Cc, Bcc in WordPress mails. Simply paste this code in “functions.php” file of your theme and replace the example mail ids with your mail ids. Moreover, the code will work with all the standard themes and WordPress themes generated with TemplateToaster web design software.

 

For adding Cc & Bcc

add_filter('wp_mail','custom_mails', 10,1);

function custom_mails($args)
{
$bcc_email = sanitize_email('example@abc.com)';
$cc_email = sanitize_email('example1@abc.com');


if (is_array($args['headers'])) {
$args['headers'][] = 'Bcc: '.$bcc_email ;
$args['headers'][] = 'cc: '.$cc_email;
}
else {

$args['headers'] .= 'Bcc: '.$bcc_email."\r\n";
$args['headers'] .= 'cc: '.$cc_email."\r\n";
}


return $args;
}

 

For adding Cc Only

add_filter('wp_mail','custom_mails', 10,1);

function custom_mails($args)
{

$cc_email = sanitize_email('example1@abc.com');


if (is_array($args['headers'])) 
{

$args['headers'][] = 'cc: '.$cc_email;
}
else 
{

$args['headers'] .= 'cc: '.$cc_email."\r\n";
}


return $args;
}

 

For adding Bcc Only

add_filter('wp_mail','custom_mails', 10,1);

function custom_mails($args)
{
$bcc_email = sanitize_email('example@abc.com)';

if (is_array($args['headers'])) 
{
$args['headers'][] = 'Bcc: '.$bcc_email ;
}
else 
{
$args['headers'] .= 'Bcc: '.$bcc_email."\r\n";
}

return $args;
}

 

Now, you have a simple and small easy script that will work out well in WordPress. Also, I am planning to write an article to create a plugin for Cc, Bcc in WordPress mail soon. Your feedback is always valuable. So please share your views.

So this was all about how to add Cc, Bcc in WordPress mail but if you are still looking to setup your own SMTP for WordPress, check out this article. Moreover, if you are all done with Mail configuration and thinking to give your site a makeover, start designing with TemplateToaster web design software.