Home / Admin / How to Add BCC to Email Notifications (for specific form)
Duplicate Snippet

Embed Snippet on Your Site

How to Add BCC to Email Notifications (for specific form)

<10
Code Preview
php
<?php
/**
 * Add BCC recipients to specific form email notifications.
 *
 * @link https://wpforms.com/docs/how-to-add-bcc-to-email-notifications/
 */
 
add_filter( 'wp_mail', function ( $args ) {
// Use WPForms_Process object to get the form ID
$wpforms_process = wpforms()->process;
// Only run this snippet on form ID 1000
if ( $wpforms_process->form_data['id'] == 1000 ) {
    // Add the BCC email address here
    $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;
});

Comments

Add a Comment