Webform Bonus Pack: email routing in webforms

Aug
02

We would like to announce the creation of the Webform Bonus Pack module which allows you to do email routing and to send submissions digests in specific formats to a configured set of emails on cron.

This blog post aims to show different approaches of email routing (i.e.conditional emailing), to explain pros and cons of these approaches, and to show how to handle email routing efficiently using Webform Bonus Pack module.

Task statement

Let's assume we have a simple order webform for a Drupal webshop. It has four fields: Name, Email, What are you interested in, and Order details.

The What are you interested in field uses a multiple select component which have the following key-value pairs:

branding|Branding
graphic_design|Graphic design
web_design|Web design
website_support|Website support
website_performance|Website performance optimization
internet_marketing|Internet marketing
seo|Search engine optimization
hosting|Hosting

Assume we have following email routing rules:

Well known solutions

1. Webform's built in abilities

It is easy to send email to a custom address on every submission. Also we are able to send E-mail to an address which is coming from any of the webform components.

In our case we need to assign available values for the What are you interested in component to be like this:

designer@example.com|Graphic design
developer@example.com|Web design
performance@example.com|Website performance optimization
other@example.com|Search engine optimization

As you can see it is easy to configure simple routing, however there are some limitations:

  • The key should be unique, hence it is impossible to use same email address for two or more keys.
  • It is impossible to send emails to multiple email addresses if a single item is selected.
  • Email addresses will be used instead of proper keys when viewing submission or downloading webform results.

As we can see, this is a fast solution, but it is not very configurable.

2. Webform PHP module

The Webform PHP module allows you to create a PHP component, which could be used to assign E-mail addresses to values (or whatever you want). In a PHP component you need to add specific PHP code that makes custom routing. Obviously in code you could read data from other components and use complex conditions. Although this is a highly configurable solution, it is very dangerous, so the module maintainer recommends against using this module unless the developer knows what he is doing.

3. Custom module

Using custom PHP code in your module for Webform validation or submission is more safe, and is also highly configurable, but it is more difficult to update routing rules and cannot be done easily by non-technical people.

Email routing using Webform Bonus Pack module

The Webform Bonus Pack module provides a mapping component, which can be easily used for email routing. Configuration is easy: you need to select the What are you interested in component as a mapped component and then add mapping key-pair values. Keys are the mapped component (e.g. What are you interested in) keys and values are emails. When items of the What are you interested in component are selected our routing component will return appropriate set of emails.

You need to select newly created Routing component as the E-Mail to address. And also don't forget to add sales@example.com as custom email address to E-mails setting form.

Now you can test how it works: When you are submitting the form select the check-boxes for Website performance optimization and Hosting. Emails should then be sent to sales@example.com, developer@example.com, performance@example.com and other@example.com.

What's next?

I think that the mapping component will be evolving in the future. It would be good to have some functionality of or integration with the Rules module. Also, of course, I will be porting this to Drupal 7. In the next blog post about Webform Bonus module I am going to talk about another interesting feature, a submodule called Webform Digest, which already has integration with the mapping component.

9 Comments

I have installed this module

I have installed this module but didn't find any difference in webform module. I don't know, where I need to assign keys(ie graphic_design) with email (abc@domain.com).

If I will be able to assign keys with email, i can use keys with values (Graphic Design)with select component in webform.

Please help me in configuring this functionality. I am new for Drupal.

Thank & Regards,
Amit

You need to add a mapping

You need to add a mapping component to your webform. Steps are:

* Enable webform_routing module
* Add fields to your webform
* Add select widget to your webform with contents like:

choice_a|Choice A
choice_b|Choice B

* Then add a mapping component to your webform with contents like:

choice_a|email-a@example.com
choice_b|email-b@example.com

* Then add an email field at the email tab for your mapping component.

Hope that helps!

Best Regards,

Fabian

What about the token, is it

What about the token, is it will work on the token, as %useremail

I'm looking for a way to

I'm looking for a way to automate the Webform manual download process by emailing a webform's results (all submissions) as a file attachment to a designated email.

Is this possible with Webform Bonus Pack?

Full detail of this issue on d.o: http://drupal.org/node/1728708

Hi Renaud, It is possible to

Hi Renaud,

It is possible to send submissions digest in xls file as attachment email. But it is available in 6.x-3.x. It is higly priority feature I am going to port to 7.x-3.x.

This module is great !! I

This module is great !! I would like to use it on a project but have noticed that it hasn't been updated for over a year. Is it still maintained or should I try to use Rules ?

Hi, thanks. Looks like this

Hi, thanks. Looks like this module has growing popularity. Now it is a time to update some code there ;)

So far, this looks good.

So far, this looks good. Haven't been able to test it yet on a server than can actually send email, but the usage is simple.

Is there a way to get access to the mapping values and use them to drive redirection to a different confirmation page, based on value of a SELECT? If so, would it be simpler than just setting up a select case statement using webform PHP?

The mail routing option is

The mail routing option is perfect and this post made it very easy to use! Thanks! I am using the 7.x branch.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options