WordPress set BCC to all e-mails

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.