Sending emails to specific department for WordPress contact forms

Conditionally sending an email to a specific department E-mail address based on the user selected option from a dropdown on your WordPress form.

Let's assume you have multiple departments within your company that handle different inquiries.

When a user fills out the form you might ask the user if the inquiry is about sales or support.

Based on the selection you can then send it to the corresponding E-mail address.

There are multiple ways to accomplish this but the easiest way to do it is to add a dropdown named "department" and adding 2 items like so:

The above example works just fine, however it is good practice to not expose an E-mail address directly into the source code of a web page (to prevent spam, because of bots being able to index it).

This is where the build in Secrets system comes into play.

You can configure secrets like below. This will allow you to set the dropdown values to be {@sales_email} and {@support_email} which will not expose the E-mail address in the source code. But by calling {department} tag it will replace the underlaying value with the actual E-mail address server side.

First go to the "Secrets" tab, and configure your secrets like so:

After configuring the secrets, you can edit your dropdown and set the values to the secret tags like so:

Demonstration on how to configure this from scratch:

Last updated