Available on: Platinum plan
Formspree allows you to set up custom routing rules that control delivery of your form submissions based on certain criteria. Routing rules can be used for:
- Sending emails to different recipients based on the value of form data, such as a drop-down select input,
- adding a recipient when a checkbox is checked, or
- sending emails to several recipients.
Here's how to get started:
Adding your first rule
By default submissions are sent to the target email of a form. However:
If you create a routing rule, the form's target email is ignored, and instead the routing rules determine notification delivery.
We recommend that you first add a default rule that will always be triggered. You can add a default rule by following these steps:
- Click the Routing tab then click Add Rule:
- Pick a recipient email address from your verified addresses, then click Save. Leave the condition as "Always match" so that, when a new submission is received, this rule will always be triggered.
At this point when a new submission is received, a notification email will be sent to the Target Email address. This is similar to the default functionality for Formspree forms.
Routing with a form drop-down menu
Let's say you have a form with a select input, allowing visitors to choose from a few different options. For example, suppose a visitor can send feedback to either the "Housewares" or "Electronics" department. Here's what this form might look like:
Here's some form HTML that accomplishes this:
<h3>Please leave your feedback below:</h3>
<form action="https://formspree.io/FORM_ID_OR_EMAIL" method="POST">
<select name="department" required>
<input name="name" type="text" required/>
<label>Your Email: </label>
<input name="_replyto" type="email" required/>
The highlighted select statement above creates a drop down menu where the user can choose either "Housewares" or "Electronics".
Adding drop-down routing rules
Let's say that you want to send notifications to the appropriate department based on the visitor's choice from the drop-down input field. To accomplish this:
- First ensure you submit the form once including the relevant input field. In this case we need to submit the form with the "department" select input. This makes Formspree aware of the new field, so it can be used when creating rules.
- Create a new rule for one of the options in the input field. First, set the Target Email to the appropriate recipient, for example "email@example.com". Then choose "Match if contained in" as the condition. Next select the input field to test for a match. In this case the "department" field. Then fill in the appropriate value from the select input. In this case we'll use "Housewares". Finally click Save.
At this point the second rule will match if, contained in the "department" field, there is the word "Housewares". When the rule matches a notification will be sent to the Target Email, "firstname.lastname@example.org".
- Now create a rule for the second option, similar to the rule above. In this case we will send a notification to "email@example.com" when the "department" field contains "Electronics".
At this point, when a new submission comes in, it will either match with the second or third rules, depending on whether the "department" field contains the word "Housewares" or "Electronics". That will cause a notification email to be sent to either "firstname.lastname@example.org" or "email@example.com".
The first rule will always match, causing two emails to be sent for the ruleset above. If you only wish to send one email notification, you can remove the first rule.
Routing with a checkbox
What if you have a form with a checkbox, and you want to send an email notification only when the checkbox is checked? For example, let's say your form has this checkbox:
Here's some form HTML for the checkbox above:
<input type="checkbox" name="urgent" value="yes">
My problem is urgent!
Adding checkbox routing rules
In order to send an email notification only when the checkbox is checked, add a rule using the "Match if not empty" Condition selecting the appropriate field for the checkbox. For example:
Sending to multiple recipients
If you just want to send an email to multiple recipients, you can do so by adding multiple rules using the "Always match" condition. Here's an example of a form that sends notification emails to both "firstname.lastname@example.org" and "email@example.com":
Routing with other Conditions
So far we've discussed adding routing rules using the "Always match", "Match if contained in" and "Match if not empty" Conditions.
For the later two Condition types, there are also negative Conditions: "Match if empty" and "Match if not contained in".
Here is a list of all the conditions, and some scenarios when you might want to use them:
- Always match: You want to send an email notification for every submission. Useful for adding multiple recipients.
- Match if not empty: You have a checkbox or text input. Useful in scenarios when you want to follow up only with certain visitors.
- Match if Empty: Useful for opt-out checkboxes. For example, you may wish to only send a notification for visitors that don't check "Please do not contact me". Otherwise let their feedback go directly to the archive, to be exported later.
- Match if contained in: You have a drop-down or text input. Useful for routing to different recipients based on the value. Can also be used to send a notification when a particular keyword is present. For example, you may want to notify the billing department if a message field contains the word "refund".
- Match if not contained in: This was added for completeness, and is still being evaluated. We may remove it in the future.