Sending Site Notifications to a BCC Address

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy but don’t provide support for code customizations or 3rd party development.

Overview

Would you like to add a BCC email address to all emails sent from your WordPress site? Adding a BCC email address is a great way to check the notifications you’re sending your users without disclosing your email address.

In this tutorial, we’ll show you how to use a PHP snippet to ensure all your site’s outgoing emails are also sent to a specific BCC email address.

Note: Be sure to install and activate the WP Mail SMTP plugin on your site before adding the code snippet provided in this tutorial.

Setup

We recommend that you copy and paste the required snippet below into a new WPCode snippet. WPCode makes it easy and safe to run code snippets on your site.

For help with adding snippets to your site, please see our tutorial on adding code snippets using the WPCode plugin.

Copy and paste this snippet to your site. On line 3, you’ll need to replace [email protected] with your desired BCC email address.

function wpms_add_bcc_email_address( $args ) {

 $bcc_address = 'bcc: [email protected]';

 if ( ! empty( $args['headers'] ) ) {
  if ( ! is_array( $args['headers'] ) ) {
   $args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) );
  }
 } else {
  $args['headers'] = [];
 }

 $args['headers'][] = $bcc_address;

 return $args;
}

add_filter( 'wp_mail', 'wpms_add_bcc_email_address', PHP_INT_MAX );

That’s it! Now you know how to successfully add a BCC email address to all the emails sent from your WordPress site.

Next, want to explore more ways to customize your WP Mail SMTP setup? Be sure to take a look at our other code snippets for more customization options.