Use Conditional Recipients
Written by the Divi Engine Documentation Team
Setup Conditional Recipients
Conditional recipients allow you to send form submissions to different email addresses based on certain conditions. This can be extremely useful when you have multiple departments or individuals that need to receive specific types of form submissions. By using conditional recipients, you can ensure that the right people receive the right messages, and that important communications are not missed.
What you will need
To get started with adding conditional recipients to your forms, you will need the Form ID and the ID of the fields you want to use in your conditions. The Form ID is a unique identifier for your form. The field IDs are also unique identifiers for each form field.
To define/find your Form ID, edit your Divi Form Builder module and within the Main Options setting add/copy the Form ID
To define/find your Field ID(s), edit your Divi Form Builder module and open the settings for your relevant field and you can add/copy the Field ID under Field Options
Note: You can use as many fields as you would like and they can be any field type. We would recommend using fields with pre-defined options such as Select, Checkbox or Radio fields as the value will be predictable.
Step 1. Create and Add your Conditional Recipient Function
Single Field Conditional Code
The below example of code needs to be added to your child themes `function.php` file. You need to replace the `$form_id` with the Form ID you have defined in the previous step. The `$form_data` sets your Field ID and the condition has to be exactly as it is defined in your form.
For this example, we have a Select field with the options Sales and Support.
Multiple Field Conditional Code
You can also create conditions based on multiple field values!
The below example of code needs to be added to your child themes `function.php` file. You need to replace the `$form_id` with the Form ID you have defined in the previous step. The `$form_data` sets your Field ID and the condition has to be exactly as it is defined in your form.
For this example, we have a Select field with the options Sales and Support and a Select Field for our products.
Multiple Forms With Different Conditions Code
You can also use this code with multiple forms! In the below example, we have two forms and they both have different conditions.
No conditions met?
If none of the conditions you define are met, the standard form recipient which is defined in your Form Builder Form Module will be used.
Step 2. Add your filter
Once you have added your function to the functions.php file you then need to add your filter to the functions.php file too. This is the bit of code that allows your function to interact with the form process.
There are two filters available according to your form type. If you are using a contact form type form then you need to use custom_contact_recipient. For any other form types please use the df_notification_recipient.
If you would like to use conditional recipients with multiple forms and some are contact forms, some are other types, please rename your filter and adjust the function name in the filter.
If you would like to use conditional recipients with multiple forms and some are contact forms, some are other types, please rename your filter and adjust the function name in the filter. An example of this can be seen below
More Support?
Please email us at [email protected] if you are unable to get our hooks working.