An image of three telephone booths represents sending different emails to different recipients based on value choices.

How to Dynamically Route Emails in Contact Form 7 on WordPress

Published on June 16th, 2024

By


In many businesses, efficient communication is key. Often, customer inquiries need to reach the right department quickly—be it sales, support, or general inquiries. This requirement is not limited to organizations! Political parties also want their respective states’ teams to be notified whenever someone joins from their state or pays membership fees.

The Contact Form 7 plugin in WordPress allows you to achieve this by dynamically routing emails based on a dropdown selection. This ensures that each query or membership alert is promptly notified to the appropriate team.

To send emails to different email addresses based on a dropdown selection in Contact Form 7 on WordPress, you can follow these steps:

Step 1: Install and Activate Contact Form 7 Plugin

An Image showing the WordPress Add Plugins section in the Dashboard highlighting Contact Form 7 Plugin

  • Go to your WordPress dashboard.
  • Navigate to Plugins > Add New.
  • Search for the “Contact Form 7” plugin.
  • Install and activate the plugin.
Step 2: Create a Contact Form with a Dropdown Field

  • Go to Contact > Add New in your WordPress dashboard to create a new form.
  • Add a dropdown menu to your form. For example:
An Image showing the code for Select option values in Contact Form7

This creates a dropdown menu where each option (Sales/Support) has a corresponding email address (sales@example.com/support@example.com) linked to it. Note the use of a pipe ('|') to separate the dropdown option from the associated email address.

When the pipe is used in the drop-down as shown above in the code, the value before the pipe (‘|’) is visible and the value after the pipe (‘|’) is invisible. To fetch the value after the pipe, we need to use the mail-tag ([your-recipient] in our case) in the mail templates. To get value before pipe, we have to use [_pipe_{field name}] ([_pipe_your-recipient] in our case).

Users can only use this pipe in drop-down, radio buttons, and checkbox components. 

Step 3: Configure the Email Settings

  • Still, in the Contact Form 7 editor, go to the Mail tab.
  • In the To field, use the mail-tag for the dropdown field. For example, see below:
An Image showing the code to dynamically select email id based on selected value in Drop-down

The shortcode/mail-tag [recipient] in the mail template will dynamically set the recipient email address based on the user’s selection.

Step 4: Add the Form to a Page or Post

  • Copy the shortcode provided by Contact Form 7 (found at the top of the form editor).
  • Paste the shortcode where you want the form to appear on the page or a post.
Step 5: Test the Form

  • Navigate to the page where you embedded the form.
  • Fill out the form, select different options from the dropdown to ensure that you send emails to the correct addresses.
Example Code for Contact Form 7

An Image showing the Form Tab code of the Contact form7 form
An Image showing the Mail Tab code of the Contact form7 form

Thus by using a pipe ('|') one can direct form submissions to different email addresses based on the user’s selection.

If you know of a better way to accomplish this utilising a plugin or custom code, please share your ideas or thoughts.

How to Dynamically Route Emails in Contact Form 7 on WordPress was last modified: June 16th, 2024 by WebNet Creatives

Comments are closed.