Sending Drupal Webform Results to Different Email Addresses
One of our students is using Drupal’s Webform module for their site’s contact form.
They asked if it was possible to send submissions to different e-mail addresses based on a choice made in the form. The student wanted to send different submissions to different departments in the company.
Yes, it is possible and we’re going to show you how.
Before we start, here are two useful links:
1) Install Webform
- If you haven’t done so yet, install and enable the Webform module: http://drupal.org/project/webform
2) Create a Webform
- Go to Add content > Webform and create a new webform.
- Add a “Select options” component to your form as in the image below.
- Click Save.
- Find the Options area.
- Place an email address on the left, then a pipe bar and then the label that you want visitors to choose.
- Click Save component.
- Finish creating the rest of your webform.
3) Customize the emails from the form
- Click the e-mails tab oin the top-right.
- Set Component value to Department.
- Click Add.
- Make sure that the E-mail to address field is set to Component: Department.
- Click Save e-mail settings.
- Your email setting will now look like the image below.
- Now visit your form and your webform will now send to different e-mail addresses, depending on the selection made under Department.
Nice trick, but what about spambots, who scan source code, and will find those addresses?
An issue is opened here for conditional emails : [url=http://drupal.org/node/687606]http://drupal.org/node/687606[/url]
Thanks for the link, Grincheux.
Looks like a useful patch. It’s a shame it missed becoming part of the core for the next release.
Does sending email based on a selected option work in the same manner if MULTIPLE options are allowed to be selected?
In other words, lets say…
I have a select options field multiple options are enabled called: Need Assistance
There are five options each with a different email that a user can select and ask for assistance.
the EMAIL TO setting for this component is set to: Need Assistance
If a user selects 3 out of the 5 select options, will an email be sent to ALL 3 of the email addresses associated with each of options selected by the user?
Is it possible to embedd a hyperlink or email address into the text of select option?
In other words, if I have a the following options listed in a select option:
0|Business Degree Information
1|Nursing Degree Information
Is there a way to list make the text “Business Degree Information” or include a hyperlink in an option list?
I tried this and can’t find the appropriate field type after creating my webform after the Drupal Webform class model. I just see Select list, but can’t figure out how to have the display be only the department rather than the e-mail address pipe and the department. Is there another select option I’m not seeing? I’d like it to be just department, but the e-mail selected when the option is selected from the list.
Nice! Thank you!
Terrible solution. Expect loads of spam coming your way.
If I have duplicate keys,this would fail eventually. Looking to use duplicate keys as email for different values.
If these are my key|value pairs the above trick is failing. please email me back if you have a solution to my scenario
Not a preferable solution as in the source the email list will be available to hackers and spamers. May be we need to use the webform hooks etc.
How to set the default email address if no options is selected from the options list. ?
You need to define the default as mentioned above.