How to get proper mail info from divi contact form

The Divi Contact Form!

To get proper mail information from the Divi Contact Form, you'll need to configure the form settings and use the correct PHP code to retrieve the form data. Here's a step-by-step guide to help you achieve this:

Step 1: Configure the Divi Contact Form

  1. Go to the WordPress dashboard and navigate to Divi > Contact Forms.
  2. Click on the Edit button next to the contact form you want to configure.
  3. In the Form Settings tab, make sure the Enable Form toggle is turned on.
  4. In the Form Options tab, set the Form Type to Email.
  5. In the Email Options tab, enter the email address where you want to receive the form submissions.

Step 2: Add the necessary PHP code

  1. In your WordPress theme's functions.php file, add the following code:
    function get_divi_contact_form_data() {
     $form_data = array();
     if (isset($_POST['et_pb_contact_form'])) {
         $form_data = $_POST['et_pb_contact_form'];
     }
     return $form_data;
    }

    This code retrieves the form data from the $_POST array and stores it in the $form_data variable.

Step 3: Use the PHP code to retrieve the form data

  1. In your WordPress theme's functions.php file, add the following code:
    function process_divi_contact_form_data() {
     $form_data = get_divi_contact_form_data();
     if (!empty($form_data)) {
         // Process the form data here
         // For example, you can use the following code to send an email:
         $to = '[email protected]';
         $subject = 'Contact Form Submission';
         $message = 'Name: '. $form_data['name']. "\r\n";
         $message.= 'Email: '. $form_data['email']. "\r\n";
         $message.= 'Message: '. $form_data['message'];
         wp_mail($to, $subject, $message);
     }
    }
    add_action('wp_footer', 'process_divi_contact_form_data');

    This code retrieves the form data using the get_divi_contact_form_data() function and processes it. In this example, it sends an email with the form data to the specified email address.

Step 4: Add the form to your page

  1. Go to the WordPress dashboard and navigate to Pages.
  2. Click on the page where you want to add the contact form.
  3. Click on the Add Module button and select Contact Form.
  4. Choose the contact form you configured earlier and click Insert.

That's it! With these steps, you should now be able to retrieve the form data from the Divi Contact Form and process it using PHP code.