Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Created October 16, 2017 15:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaFFik/6ebf5c860e9e9b053a64f264a08f019b to your computer and use it in GitHub Desktop.
Save slaFFik/6ebf5c860e9e9b053a64f264a08f019b to your computer and use it in GitHub Desktop.
WPForms: add BCC email header to notification emails
<?php
add_filter( 'wpforms_email_headers', function ( $headers, $emails ) {
// APPLY THE BCC TO THIS FORM ID ONLY.
// CHANGE THE ID TO THE FORM YOU NEED. OR REMOVE THE WHOLE IF BLOCK IF NEEDED FOR ALL FORMS.
if ( 384 !== $emails->form_data['id'] ) {
return $headers;
}
// CHANGE THIS EMAIL ADDRESS TO YOURS:
$bcc_email = 'test@example.com';
$headers .= "Bcc: $bcc_email\r\n";
return $headers;
}, 10, 2 );
@Bobswesternshirt
Copy link

Hi- I wanted to try this, but where do I put the file?
Thanks!

@bitridge
Copy link

Hi- I wanted to try this, but where do I put the file? Thanks!

I think it should go intp functions.php file

@StefsterNYC
Copy link

StefsterNYC commented Feb 24, 2024

Yes this goes in your functions.php file @Bobswesternshirt and @bitridge and if you want it to do all forms you'd simply clear the condition

<?php

add_filter( 'wpforms_email_headers', function ( $headers, $emails ) {
    // CHANGE THIS EMAIL ADDRESS TO YOURS:
    $bcc_email = 'test@example.com';

    // Add BCC email to the headers
    $headers .= "Bcc: $bcc_email\r\n";

    return $headers;
}, 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment