Route Contact Form 7 Submissions to Different Email Addresses by User Selection

Route Contact Form 7 submissions to different email addresses

When a website handles several departments or services, a contact form often has to go to a different email address depending on what the visitor selected. Contact Form 7 supports this out of the box with “pipes”, without any PHP code.

Problem: A Contact Form 7 form has a department or topic dropdown, and each submission must go to the email address of the selected department.

Step 1. Add a select field with pipes

Open the form in the Contact Form editor, switch to the Form tab and add a select field. The pipe character (|) separates the label the visitor sees from the value that is used in the email. One option can go to several recipients, separated by commas:

[select* business-line class:form-control id:sel first_as_label
    "- Please Select -"
    "Sales Enquiries | sales@example.com, sales2@example.com"
    "Product Information | products@example.com"
    "Partnerships | partners@example.com"
    "Career Opportunities | hr@example.com"
    "Developer Program | dev@example.com"
    "Other | info@example.com"]

The email addresses never appear in the page source: the visitor’s browser only sees the labels, and Contact Form 7 replaces the label with the value on the server.

Step 2. Use the field in the To field

Switch to the Mail tab. In the To field, enter the mail-tag of the select field, in this example [business-line]. Contact Form 7 replaces it with the email address(es) of the option the visitor selected.

Show the selected label in the email body

In the message body, [business-line] would also output the email address. To show the label the visitor chose (“Sales Enquiries”), use the raw tag: [_raw_business-line].

NOTE: Pipes work only with select, radio and checkbox fields. To route by the value of a text field, you need PHP: change the recipient in the wpcf7_before_send_mail action.