I've had a few requests recently for a feature where different people receive emails from a form, based on what the user entered.
simpleContact Pro stores a list of email recipients in its database. This is more secure than exposing recipients in the form code (e.g. as hidden fields) and you can have as many recipients as you want. They will all receive an email when someone completes your form. In some cases however, you might want different people to receive those messages.
Ordinarily, the recipients list is retrieved from the database and an array is constructed. The form processor loops through that array of email addresses and sends the messages. The best way to achieve the desired effect of this hack is to selectively override the recipients list before it is looped through.
In this example, I've used a country menu. You can find a list of countries of the world in this forum to help you build such a menu quickly. If the user selects "United Kingdom" or "United States" we'll override the recipients list.
1) Your recipients list
Use the recipients list in your sc_admin to specify the default recipients. These are the email addresses that will receive the form submissions unless we specifically override them.
2) Overrides
This hack assumes that the name of the field is obj_10. You will need to amend the code to reflect the name of your field, the values you want to respond to and the email addresses you want to send messages to.
Open sc_admin/include/contact.php
Insert your version of the following code after line 270. Here's a simple example:
if ($posted["obj_10"] == "United Kingdom") {
$recipients = array("ukenquiries@yourwebsite.com");
}
Here's a slightly more complicated example:
if ($posted["obj_10"] == "United Kingdom") {
$recipients = array("ukenquiries@yourwebsite.com");
} else if ($posted["obj_10"] == "United States") {
$recipients = array("usaenquiries@yourwebsite.com","john@yourwebsite.com");
}
Note that the second example has two conditions (you can extend it by adding more "else" conditions). It also demonstrates how to override the recipients list with a new list that has more than one email address in it.