WordPress set BCC to all e-mails

WordPress sometimes we need to also send email on BCC. It’s not possible to set BCC on all emails one by one. WordPress provide hook functionality using hook we can set the BCC on all emails. it’s the smart way to used hook instead of did more coding.

So let’s see how we can set the BCC for all emails using WordPress hook. Write the WordPress hook on the current theme functions.php file.

function theCodingStuff( $args ){
    $emails = $args['to'];
    $emails = explode(',', $emails);
    if( is_array($args['headers']) ){
        foreach ($emails as $key => $value) {
            $args['headers'][] = ' Bcc: youremal@mail.com';
        }
    }else{
        $headers = $args['headers'];
        foreach ($emails as $key => $value) {
            $args['headers'] = $headers.' Bcc: youremal@mail.com';
        }
    }
    return $args;
}
add_filter('wp_mail','theCodingStuff');

Using the wp_mail hook we can set the BCC on all email sent by WordPress system.

If you face any issue after using wp_mail hook write the comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s