‘Conditional’ Recipients
Suppose you want to send the form submission email conditionally, based on a form input.
For example, there is a ‘department’ drop down in the form. Depending on the selection in the drop down, the email should be sent to the corresponding address. (sales@mycompany.com, billing@mycompany.com etc)
The current version of Simfatic Forms (3.2) does not have the feature to set a condition for sending the email.
However, we have extension modules for rescue. Extension modules can be used to extend or change the behavior of the server side script. (See: extension modules in Simfatic Forms help.)
First, we need a place-holder email address in the ‘recipients’ list
In the setting above, dept@user5.com is the place-holder email.
The extension module
The extension module is written in PHP. Download the sample extension module here.
You can edit the extension module in any text editor.
Here is how it works:
The extension module overrides call-back function BeforeSendingFormSubmissionEMail(). When the script is sending the form submission email, it will call BeforeSendingFormSubmissionEMail() , for each of the recipients. Here, we can change the recipient address, just before the email is sent.
We check the selected value of the ‘department’ drop down and update the recipient to the corresponding email:
The code is not that complicated.
function BeforeSendingFormSubmissionEMail( &$receipient,&$subject,&$body) { if(false !== strpos($receipient,'Admin')) { //Admin gets all the emails! return true; } elseif(false !== strpos($receipient,'dept@user5.com')) { $dept = $this->formvars['Department']; switch($dept) { case 'Sales': $receipient = 'Sales<sales@user5.com>'; break; case 'Service': $receipient = 'Service<service@user5.com>'; break; case 'Technical': $receipient = 'Technical<technical@user5.com>'; break; case 'Billing': $receipient = 'Billing<billing@user5.com>'; break; } } return true; }
You can edit the extension module and customize it for your needs.
Loading the extension module
First, enable extension modules in the ‘form processing options’ page.
Then, in the extension modules page, press the ‘Add module’ button and select the extension module (edited and made ready – above)
Proceed to ‘take the code’ page and upload the form.
Download
conditional-email.zip
The .zip file contains the extension module and a Simfatic Forms template file of the form used to create and test this extension module.