How to Send Contact Form 7 Submissions to Different Emails Based on User Input
Content
One of the most common challenges WordPress users face with Contact Form 7 is routing form submissions to different email addresses based on a user's selection or input. This is a powerful feature for businesses that need to direct inquiries to specific departments, locations, or team members.
For instance, you might want a form on your 'Request a Quote' page to go to your sales team, while a form on your 'Support' page goes to your technical staff. A more advanced use case, as seen in the sample threads, involves sending submissions to different emails based on a dropdown selection (like 'Events' vs. 'Contact') or even dynamic data like a user's zip code.
Why This Happens
By default, a Contact Form 7 form is configured to send all submissions to a single, predefined email address entered in the Mail tab. The plugin's core functionality does not include a built-in, point-and-click method to make the recipient address dynamically change based on form data without some configuration.
Common Solutions
Solution 1: Using Pipes for Selectable Recipients (Simple Method)
The simplest way to achieve conditional email routing is by using the selectable recipient with pipes technique. This method is ideal when the choices are fixed and known in advance, such as a dropdown menu for 'Department'.
- In your form, create a dropdown, checkbox, or radio button field where the user makes their choice. For the option values, use the pipe character
|to separate the label the user sees from the actual email address.
[select your-department "Sales|[email protected]" "Support|[email protected]" "Events|[email protected]"]
- In the Mail tab of your form settings, locate the To field. Instead of a hardcoded email, insert the mail-tag for the field you just created, in this case,
[your-department].
Now, when a user selects "Sales" from the dropdown, the form will be sent to [email protected]. This method is officially suggested by the Contact Form 7 team in their documentation.
Solution 2: Using a Custom Field for Dynamic Recipients (Advanced Method)
For more complex scenarios, such as pulling an email address from a post's custom field, a simple pipe won't suffice. This requires using a WordPress filter hook in your theme's functions.php file.
The following code snippet demonstrates how to change the recipient email based on a value from a custom field named 'email':
add_filter('wpcf7_mail_components', 'custom_change_recipient', 10, 3);
function custom_change_recipient($components, $wpcf7_get_current_contact_form, $wpcf7_mail) {
// Get the current post ID
$post_id = url_to_postid($_SERVER['HTTP_REFERER']);
// Check if the custom field 'email' exists for this post
$recipient_email = get_post_meta($post_id, 'email', true);
// If the custom field has a value and it is a valid email, use it
if (!empty($recipient_email) && is_email($recipient_email)) {
$components['recipient'] = $recipient_email;
}
// Always return the components array
return $components;
}
Important Note: Editing your theme's functions.php file directly is not recommended, as your changes will be lost when the theme updates. It is better to use a child theme or a code snippets plugin. Always test code on a staging site before deploying it to your live website.
Conclusion
Whether you need a simple dropdown selector or a complex dynamic solution, Contact Form 7 provides the flexibility to route emails conditionally. For most users, the pipe method (Solution 1) is the quickest and most reliable approach. For developers needing deeper integration with WordPress data, the filter hook method (Solution 2) offers unlimited customization.
Related Support Threads Support
-
Hidden fieldhttps://wordpress.org/support/topic/hidden-field-18/
-
Two webhook with the same keyhttps://wordpress.org/support/topic/two-webhook-with-the-same-key/
-
Display translations for select options in e-mailhttps://wordpress.org/support/topic/display-translations-for-select-options-in-e-mail/
-
Custom Fields as E-Mail recieverhttps://wordpress.org/support/topic/custom-fields-as-e-mail-reciever/
-
Feeding in ‘To’ email address from ACF fieldhttps://wordpress.org/support/topic/feeding-in-to-email-address-from-acf-field/
-
sender emailhttps://wordpress.org/support/topic/sender-email-16/
-
getting the submitter IPhttps://wordpress.org/support/topic/getting-the-submitter/
-
Send only filled fieldshttps://wordpress.org/support/topic/send-only-filled-fields/
-
Get default from form fieldhttps://wordpress.org/support/topic/get-default-from-form-field/
-
Can we send conditional email?https://wordpress.org/support/topic/can-we-send-conditional-email/
-
Trying to send a form to a different mail depending drop-down selectionhttps://wordpress.org/support/topic/trying-to-send-a-form-to-a-different-mail-depending-drop-down-selection/
-
User Meta Datahttps://wordpress.org/support/topic/user-meta-data-5/
-
Reminder mails for contact form 7 registrantshttps://wordpress.org/support/topic/reminder-mails-for-contact-form-7-registrants/
-
Form email depends on the ZipCodehttps://wordpress.org/support/topic/form-email-depends-on-the-zipcode/
-
Dynamic mail-tagshttps://wordpress.org/support/topic/dynamic-mail-tags/
-
Hidden fields inside conditional logichttps://wordpress.org/support/topic/hidden-fields-inside-conditional-logic/
-
API calls with return data for processinghttps://wordpress.org/support/topic/api-calls-with-return-data-for-processing/
-
Sender to receive a copy of his email – how to ?https://wordpress.org/support/topic/sender-to-receive-a-copy-of-his-email-how-to/
-
get-field input -> To: field of the webformhttps://wordpress.org/support/topic/get-field-input-to-field-of-the-webform/
-
email field and buttonhttps://wordpress.org/support/topic/email-field-and-button/
-
Send mail based on form field response?https://wordpress.org/support/topic/send-mail-based-on-form-field-response/
-
Hot to manage more than one variable in URL with GEThttps://wordpress.org/support/topic/hot-to-manage-more-than-one-variable-in-url-with-get/
-
Using default values from shortcode for dynamic recipientshttps://wordpress.org/support/topic/using-default-values-from-shortcode-for-dynamic-recipients/
-
Custom email tag or something else?https://wordpress.org/support/topic/custom-email-tag-or-something-else/
-
Delay timing of autoresponderhttps://wordpress.org/support/topic/delay-timing-of-autoresponder/
-
If elsehttps://wordpress.org/support/topic/if-else-3/
-
Access reply-to header in functions.phphttps://wordpress.org/support/topic/access-reply-to-header-in-functions-php/
-
Question for possible new featurehttps://wordpress.org/support/topic/question-for-possible-new-feature/
-
Emoji’s on reply mailhttps://wordpress.org/support/topic/emojis-on-reply-mail/
-
Threading form replieshttps://wordpress.org/support/topic/threading-form-replies/