Sending Site Notifications to a BCC Address

This tutorial will show you how to use a PHP snippet to ensure all outgoing emails through Easy WP SMTP are also sent to a specific BCC email 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.


Before adding the snippet below, make sure to install and activate Easy WP SMTP on your WordPress site.

Setup

To proceed, copy and paste the snippet below to your site. When adding the snippet to your site, you’ll need to replace [email protected] on line 9 with your desired BCC email address.

<?php
/* Send Site Notifications to a BCC Address  
 * 
 * Original doc: https://easywpsmtp.com/docs/sending-site-notifications-to-a-bcc-address/
*/

function ewps_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', 'ewps_add_bcc_email_address', PHP_INT_MAX );

Note: If you’re at all unsure of where to add the snippet, please see WPBeginner’s tutorial for details on how to add custom code snippets to WordPress.

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