I recently had a project where we needed to setup a webform to request more information about training events that were hosted around the world in different cities. Depending on what city the event was in the form needed to be sent to a different email address. The issue I ran into though was several cities (options) needed to be sent to the same email address (keys).
The basic setup for this is on the webform configuration page you need to setup one of your fields to be a ‘Conditional e-mail recipients.’ In my case I have a field called ‘Workshop’ which has a “safe_key|Some readable option” setup within the Options field that I will use to send the email to so I select it.
At first I added in all my values let’s say they are as follows:
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
When I go to save the field I just get an error saying that “Options within the select list must be unique. The following keys have been used multiple times:”
And lists the keys that are duplicates.
The issue is the email address is the key and all keys must be unique. I don’t want to setup a different email address for every option in my list so I needed to figure out a way to make it work.
I thought maybe I could add “?subject=Oklahoma City” to the end of the key which would make each one unique but it did not work. I was able to save the field but the emails never came through and I got no errors when submitting the form or in the Drupal error log.
My last thought was what would happen if I added spaces to the end of the key? So for in my example above I used the following values:
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
So you can see that the first key has no spaces, the second duplicate key has one space and the third has two spaces. You can continue this out for however long you need. In my real life scenario I had to use seven and eight spaces on some of my keys.
I saved the field and tested the form and the emails came through just fine to the respective email address defined in the key value.
If this helped you out please let me know by leaving a comment below or giving me a shout out on twitter @rgbivens