Community Documentation

Conditional recipients

Last updated June 13, 2011. Created by batigolix on June 23, 2008.
Edited by quicksketch. Log in to edit this page.

To use the conditional recipient you add a webform component of the type "select".

While building the webform:

  • Click the "Webform" tab that lists components in the form
  • Enter name of field, e.g. "Kind of inquiry"
  • Choose "select"
  • Click "add"

The "Edit component" screen appears

  • Enter a Label and Field key e.g. "Kind of inquiry", "kind_inquiry"
  • In the field "options" add a couple of key-value pairs like

info@example.com|General information
johnpaul@example.com|Sales question
joseph@example.com|Technical question

The user will be presented the readable option while the key remains invisible.

  • Save your changes
  • Select "Configuration" and choose "Kind of enquiry" under "Conditional e-mail recipients"

After the component has been set up, you now need to configure the e-mail.

  • Under the "Webform" tab, click the sub-tab for "E-mails".
  • Choose the component you set up with e-mail keys to be the recipient and click "Add".
  • Configure the e-mail setting as needed and save.

Comments

But the email is still in the source code

Maybe I'm missing something here, but isn't the email still readable in the source code? I'd like to avoid having readable emails in the source, even though they aren't visible to a typical form user.

I found this thread

Link to issue

Doesn't really solve the issue.

To be clear: At this writing (January 2011), this technique still results in email addresses being stored in clear text in the HTML. Email-harvesters will find them without a problem.

Conditional email recipients

I've used webform successfully in other places. I'm a bit stymied on this one.

I have a select list with five items:
user1@place.com|one
user1@place.com|two
user2@place.com|three
user2@place.com|four
user2@place.com|five

The form displays for the selection field.
two
five

Disappearing Conditional Email recipients

I have the same issue where I have various countries (in the select list) associated with the same email. So, if region one and region two have the same email address only the first option (region one) appears in the select list.

quicksketch referred me to:

I found this website which allow webforms to use the same key value for multiple options.

http://www.interworks.com/blogs/gbivens/2010/06/04/tricking-drupal-webfo...

Here is an example:

usa@example.com|Oklahoma City - June 2010
usa@example.com |Tulsa - July 2010
usa@example.com |Stillwater - July 2010
gb@example.com|London - August 2010
gb@example.com |Manchester - September 2010

I recently ran into both of the issues commented on above (that recipient addresses must be unique, and addresses are exposed in the page markup).

My solution was to use hook_mail_alter() to set up a list of email "aliases" (such as "orders_at_example"), that are replaced with actual email addresses when they appear in the to: field when Webform sends the message via drupal_mail().

So in Webform you set up a select with something like this:

orders_at_example|Orders
customer_service_at_example|Customer Service
technical_support_at_example|Technical Support

And then in hook_mail_alter() you replace "orders_at_example", "customer_service_at_example", and "technical_support_at_example" with the actual email address (or addresses).

So a really simple example would look like the following:

<?php
/**
* Implementation of hook_mail_alter().
*/
function emerj_overrides_mail_alter(&$message) {
 
$search = 'orders_at_example';
 
$replace = 'orders@example.com';
 
$message['to'] = str_replace($search,$replace,$message['to']);
}
?>

More Detailed Example

I've posted a more detailed explanation and example using hook_mail_alter() on my blog if anyone needs it.

-Eric

getting content from the database

Hello friend,
is it posssible to get the data ( columns email id, state) from the database and to display it in the webform select component.?? then i will use Conditional e-mail recipients for this one.. i am struck with how to get the database content. If you know , plz informe me.. Thanks in advance.

< ---- Maddy ----->

Reusable module to create email aliases

I ran into this issue and didn't want to make user email addresses public either, so I created a reusable module that effects fake email address aliases. So in an admin panel you can just enter aliases to reuse across your site (including the aforementioned webform options).

Say you want to protect Amy, Bob, Carla and Doug's email addresses in a webform with conditional email recipients:

  • For Email Aliases at /admin/settings/email-alter you'd enter:
    corporate@example.net | Bob@example.net, Carla@example.net, Doug@example.net
    meetings@example.net | Amy@example.net, Bob@example.net
    legal@example.net | Carla@example.net
    help@example.net | Amy@example.net, Bob@example.net, Carla@example.net
  • In the webform select options you'd enter:
    corporate@example.net|Corporate
    meetings@example.net|Meetings
    legal@example.net|Legal
    help@example.net|Help

I posted my module at https://github.com/msmithgu/email_alter for anyone that runs into a similar issue.

can you have more than one

can you have more than one email address per option?
So what If i wanted

example@email.com, example2@email.com| No

(no being a check box)

Yes, you can send to more than one

but I think only as long as they are unique

So..

person1@foo.com,person2@foo.com|Apples
person3@foo.com|Pears
person4@foo.com|Grapes

but not

person1@foo.com,person2@foo.com|Apples
person2@foo.com|Pears
person3@foo.com|Grapes

at least not without using hook_mail_alter()

hth,
Anne

Strange...

Strange if it is working? I found this in the issue queue indicating that it should not be working:
#339416: Multiple email address for an option in the Options field?

Clarification

Webform does not allow multiple e-mail addresses within a single select list option. It does allow multiple e-mail address to be used on the main e-mail configuration options, which is accessible only to users that may edit the actual Webform node.

EDIT: Well it seems that Webform does support multiple e-mails in select lists or hidden fields. The current code clearly seems to support it.

Nathan Haug
creative graphic design        w: quicksketch.org
& software development       e: nate@quicksketch.org

multiple email recipients partial EASY solution

The + trick would not work for us but I have no time to do custom modules for our launch. Here is a simple solution (but still leaves email addresses for harvesting). Make the values unique by adding a number to what would be duplicate values...

lewis@x.com,cole@x.com,board@x.com|Board of Directors
webmaster@x.com,custsvc@x.com|Web Site Issues
webmaster@x.com,custsvc@x.com,1|Online Orders
custsvc@ex.com| Customer Service
custsvc@x.com,1| Key Contact Program
jobs@x.com|Employment/Jobs
custsvc@x.com,2|Recycled Cheese
recreate@x.com|Recreation
wtrcserv@x.com|Cheese Conservation Rebate Programs

btw - this is not my idea I am just passing it along and seemed to work for us on Acquia Drupal v6 iis7 win2008 w/Exchange as mailserver.

As far as I can tell, this

As far as I can tell, this does not work.

Storing value rather than key?

Is there a way to implement this as shown, but store the value (e.g., General information) in the database rather than the key (info@someorganisation.va)? I'm sure it's a little snippet under Additional Processing... but this seems like a pretty common use case.

I'm specifically thinking about the Table and Download report views...

Avoid sending selected values to all recipients

Is it possible to avoid sending information to all recipients of the selected values that are not related to their e-mail?

Examle:

bob@mail.com|newsletter on music
anne@mail.com|newsletter on non-fiction
peter@mail.com|newsletter on fiction

A user selects newsletter on music and newsletter on non-fiction and presses "Send form"

Now both Bob and Anne gets an e-mail where they can see both selections.
I would like bob to only see that the user has selected the newsletter on music which is relevant to him.

Configuration Button

I need someone to put me out of my misery...unlike everyone else, I seem to be having trouble with something super basic - finding the "Configuration" link.

It's this step:
Select "Configuration" and choose "Kind of enquiry" under "Conditional e-mail recipients"

I mean, I assumed it meant the regular configuration in the main admin menu, but, the only option I have there is Content Authoring > Webform Settings. And I can't find anything about "Conditional Email Recipients." This is the same page that links to the "Configure" option beside the webform module on the modules menu item.

I am begging someone to just tell me what the heck I should click after saving my select list. I'm back on the webform tab that displays all the fiels on my webform and the options that I have are "Form components," "emails," and "form settings."

On, and I'm using D7 with the latest release of webform.

Apparently in D7, you can

Apparently in D7, you can just skip this step.

I added in the key/values as demo'ed and then added that component under the Emails button. It sends it to the value entered, no problem. But I didn't specify anything about "Conditional Emails" anywhere. Is this just how it's done in D7 or am I missing something?

Hi everyone, Did this get

Hi everyone,

Did this get solved? I also wanted to use multiple emails for different departments in a select list but that functionality is no use if the emails are printed in the source code.

Sam.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 5.x, Drupal 6.x, Drupal 7.x
Audience
Site administrators

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here