Adding BCC to Divi Contact Form

by Aug 24, 2021IT Tips, Wordpress2 comments

The Divi contact form allows you to send to multiple email addresses by opening the properties of the form and entering multiple comma separated email addresses but they end up all in the To: field

Adding BCC to Emails using a functions.php Snippet

You need to edit your functions.php and add the below code. functions.php is located under wp-content/themes/<theme_name>/

Possible Locations of the Divi functions.php file

# if using Divi without a child theme
wp-content/themes/Divi/functions.php

# if using child theme replace 'divi-child' with whatever the directory name is of your Divi child theme.
wp-content/themes/divi-child/functions.php

The following code snippet allows you to silently add another email address to emails sent from your WordPress site as a BCC

<?php

add_filter('wp_mail', 'custom_mails', 10, 1);

function custom_mails($args)
{
    $bccEmail = sanitize_email('[email protected]');
    # e.g. 
    # $bccEmail = sanitize_email('[email protected]');

    if (is_array($args['headers'])) {
        $args['headers'][] = 'Bcc: ' . $bccEmail;
    } else {
        $args['headers'] .= 'Bcc: ' . $bccEmail . "\r\n";
    }

    return $args;
}

This is the original website I got this code from

2 Comments

  1. Martin

    doesn't work.

    Reply
    • James McDonald

      From the emails I get from Divi powered websites all over the world because people have forgotten to take my email address from the code I respectfully disagree ;).

      Are you sure you are putting the code in the right place?

      Do you have email working from the website itself?

      To check this you can install a plugin such as Check & Log Email https://check-email.tech/ by checkemail and try and send a test email. If your email isn't working, typically neither will the above code.

      If email is not working, here are some options to get emails from your forms:

      • Use a service like Mailgun or another email delivery provider. Create an account install the email providers plugin and configure DNS with their SPF/DKIM settings and you should have reliable email delivery.
      • Create and embed a jotform.com form which will handle the submission and sending of emails
      Reply

Leave a Reply to James McDonald Cancel reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.