Documentation ⇢ Dynamic Destination Email

Sometimes, we need to send the result of the form to different email address based on selection made by the user. The selection could be made through Drop Down field or Multiple Choice field or even Checkboxes field.

There is no option from within MachForm Admin Panel to allow you doing this. However, as of MachForm 3.2, we provide an easy way to do this simply by modifying one file and entering the email address list there.

The Goal

Let say we have a form with ID number 7, the URL would be something like this:

The form is a simple contact form and has a DropDown field:

Our goal is to configure the form so that the form is being sent to different email address based on the selected person.


View HTML Source

First we need to know the element number of the DropDown field. To do this, right click on the form and view the HTML source of the form.
You should see something like this:

Look into the name attribute of the dropdown field and you can see that the dropdown field is having element id number: 1.

Edit custom_hooks.php File

Next you need to edit machform/hooks/custom_hooks.php file. Around line 11 you should see this line of code:

global $mf_hook_emails;

Right exactly below that line, add this block of code:

$mf_hook_emails[7]['element_id'] = 1;

$mf_hook_emails[7]['John Doe']      = '';
$mf_hook_emails[7]['Richard Miles'] = '';
$mf_hook_emails[7]['Jane Roe'] 	    = '';

That’s all the code you need to add. You need to adjust the above code with your own form id number, element id number and email addresses.

Enable Email Notification

After doing the above code, save the file and don’t forget to enable email notification of your form.
Go to your email settings page and enable the “Send Notifications to My Inbox” checkbox. You can enter any email address there (any bogus email address such as should be fine either) because it won’t be used. This only being used to trigger the email notification function.

More Customization

What if John Doe has three email addresses and I would like to send it to all three addresses?

Simple, you can put all those email addresses and separate them with commas, like this:

$mf_hook_emails[7]['John Doe'] = ',,';

How do I do this for my other forms?

Simply add another block of code, similar as above (with different id numbers though) and put the new code below the existing code.

What field can I use for this modification?

You can use Multiple Choice, Drop Down or Checkboxes.

If you are using Checkboxes, the functionality is a bit different. Instead of sending the result of the form to one email selection, it will send the result of the form to any selected option of the checkboxes. So let say you have a checkboxes with three options, each having its own email address, and the user select all those three options. Then the form will be sent to all those three email addresses.

Is this safe? Is the email address being displayed within the form?

Yes, absolutely safe! Your email addresses are 100% hidden and can’t be seen by any spam bot, because the email addresses are being stored on the PHP file (server side). So it won’t be disclosed within the HTML code of your form.