Send emails with a custom/templated body (and subject, to addresses and from addresses)

Oliver Coleman - July 2, 2008 - 05:57
Project:Webform
Version:6.x-3.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:quicksketch
Status:closed
Description

The attached module allows creating multiple email profiles, with each profile allowing setting of the to email address(es), to email address(es) based on component values, email subject, from address, and the email body/message. Each of these fields has the option of the default webform value, a component value or a custom value. The custom body option can contain variables/tokens that will be replaced by their corresponding value; component values may be referenced as variables in the body with the format %cid[id] or %c[field key].

Emails get sent upon a new submission (like standard Webform).

The body/bodies may be optionally converted to plain text or CSS added to the emails with the options in the Webform Mail global settings page.

The email profile settings are displayed in a new tab on the webform node editing pages. The standard email settings are also relocated to this tab.

This module was created to allow easily creating highly configurable petitions and email campaign tools, but it's not specific to these functions.

The intention is for this to be a sub-module, but perhaps it would be better as a patch? I don't think it should really be a module in it's own right.

AttachmentSize
webform_mail-beta1.tar_.gz12.59 KB

#1

Oliver Coleman - July 2, 2008 - 23:59

Improved module help text.

AttachmentSize
webform_mail-beta2.tar_.gz 12.72 KB

#2

quicksketch - July 3, 2008 - 02:53

Wow. Nice.

I like the approach here. Moving Email settings to another tab both makes it more apparent that there are tabs (I get frequent requests from people that just don't see the tabs at all), and clears up a bit of the normal form.

However, the new page is more confusing than it was before the changes. Some notes:

- New e-mail settings are called "profiles", and yet they only apply to a single Webform? The word "profile" indicates to me it would allow me to reuse the e-mail settings from another webform.
- The e-mail form is already a bit daunting, repeating 2 or more times is even more daunting!
- This approach could render the "Conditional e-mail recipients" obsolete. If you can make multiple e-mails, instead of using conditional recipients, just make another e-mail for each recipient. The "TO" e-mail address would basically need to receive the same treatment as the FROM and SUBJECT to make this work.
- If this were integrated into the module, the "Default" settings probably wouldn't be needed, or they should include the
template area for the e-mail body also.

My bottom line feeling is that this is generally a pretty good enhancement, but we'd need to rework quite a bit of the e-mail system to integrate it properly. With the new ability, some of the current features either don't make sense or are too cumbersome to be repeated in a form several times. This functionality would be much better served as a patch, rather than as a separate module.

#3

Oliver Coleman - July 3, 2008 - 04:50

(I get frequent requests from people that just don't see the tabs at all)
This might be a theme issue, if the theme doesn't support secondary tabs/local tasks. Though the only time this has happened to me is when developing a theme and removing the line that printed the secondary tabs! So I guess at least most themes support secondary tabs.

- New e-mail settings are called "profiles", and yet they only apply to a single Webform? The word "profile" indicates to me it would allow me to reuse the e-mail settings from another webform.
Yep, they only apply to a single webform (might be nice to have something like in CCK where a previously created fields settings can be applied to another node type). "Profile" was the first word that popped into my head, I'm open to suggestions for another name...

- The e-mail form is already a bit daunting, repeating 2 or more times is even more daunting!
I guess this is the old flexibility vs ease-of-use. Personally I don't find the form daunting, especially with the way the radio options are themed with the option setting next next to the radio selector (nice work on that one!) I don't think it would be a good idea to remove flexibility, but perhaps the form can be simplified using the methods discussed in the next paragraph...

- This approach could render the "Conditional e-mail recipients" obsolete. If you can make multiple e-mails, instead of using conditional recipients, just make another e-mail for each recipient. The "TO" e-mail address would basically need to receive the same treatment as the FROM and SUBJECT to make this work.
I'm not sure that this would work nicely (if I understand you correctly). If the suggestion is to remove the existing conditional email checkboxes, and modify the to address field to have the same options as the from address field, I can see a couple of problems:

  • To send the same email to some hard-coded addresses AND some component value addresses would require duplicating profiles (this could be fixed by using checkboxes instead of radios),
  • Only one component value could be selected at a time from the select box (unless it was a multi-select box which might not look so good on the form, but perhaps better than having the separate fieldset with checkboxes for conditional component-based to addresses).

- If this were integrated into the module, the "Default" settings probably wouldn't be needed, or they should include the template area for the e-mail body also.
Yes, the default settings form becomes superfluous, I left it there simply to avoid breaking anyone's site. However if this were integrated into webform it would be easy to make an update that copied existing default settings to an email profile (or whatever it gets called) to allow removing the default form without breaking existing settings.

This functionality would be much better served as a patch, rather than as a separate module.
A patch it is! I can probably rework it as a patch once the interface and functionality is finalised.

#4

Richard_1618 - July 17, 2008 - 13:36

Will there be an upgrade available for 6.x for this patch, would be sincerely appreciated

#5

drupal.naresh - December 15, 2008 - 16:51
Version:5.x-2.0» 6.x-2.3
Assigned to:Anonymous» drupal.naresh

This will add the Email Body for the Webform Configuration. This will help in setting the mail body for the webform. You can even use the form components in the body that will replace data filled in the form [ Eg. %title can be added in the body which will be replaced when sending mail.]. I hope this will help alot :).

Please let me know if you have any problems.

Override the .install file and .module file from the .zip in the webform module.

AttachmentSize
webform_patch_for_email_body.zip 26.97 KB

#6

Oliver Coleman - January 5, 2009 - 23:39

Here's a new version of the original webform_mail module that fixes two bugs (one rather critical, not sure how this slipped by):
5.x-1.1 2009-01-06
- Fixed bug causing only first recipient email address to be used
- Fixed bug where tokens weren't substituted in subject, from name, or from email

In a previous post I said I'd make this module into a patch for webform (instead of a module), but I never did as I just don't have time and the module works as is. Apologies for not doing what I said I'd do! Of course I'd love for it to still be integrated into webform, so if anyone else would like to make it into a patch then go right ahead!

AttachmentSize
webform_mail-5.x-1.1.tar_.gz 12.83 KB

#7

mrthrelfall - March 9, 2009 - 10:28
Version:6.x-2.3» 5.x-2.6
Category:feature request» bug report
Assigned to:drupal.naresh» Anonymous
Status:needs review» active

Hi,

This is much needed module and overall looks very good. However, I have a couple of questions/comments:

1. What is the rational behind using the syntax %c[...] for substitutions rather than !.. (which would then make it consistent with the user settings for registration emails) or instead using the Tokens module?

2. Any component type that sets it's values as arrays (i.e., date, time, select) does not get displayed in emails in my testing because the function _webform_mail_filter_body() does not theme the values. Shouldn't the replace[] array be set as in something like:

        if (function_exists('theme_webform_response_mail_'.$component['type'])) {
          $replace[] = theme('webform_response_mail_'.$component['type'], $submission[$cid], $component);
        } else {  
          $replace[] = $submission[$cid];
        }

where we create the required theme functions for each component that requires this treatment?
In the attached I have taken the equivalent theme_webform_mail_xxx() functions from the webform components and included them as webform_response_mail_xxx() in the attached along with the above code. The only difference in the theme functions compared with their originals is that I've removed the adding of labels in the output. If this 'module' and webform where combined then it would probably be better to refactor the original theme_mail_xxx() functions to allow for turning the label on/off to satisfy both needs.

The attached is for Webforms 5.x-2.6.

Any thoughts?

AttachmentSize
webform_mail.zip 14.19 KB

#8

quicksketch - April 14, 2009 - 20:56
Title:Send emails with a custom body (and subject, to addresses and from addresses)» Send emails with a custom/templated body (and subject, to addresses and from addresses)
Category:bug report» feature request
Status:active» needs work

Marking CNW to indicate this issue contains code.

#9

TravisCarden - May 11, 2009 - 03:04

This will be exciting if it finds its way into 6.x! Subscribing.

#10

okmi - May 27, 2009 - 22:18

subscribing. this is a critical piece that we need for this module to do what we need :) thanks for all your hard work!

#11

quicksketch - May 27, 2009 - 22:47
Version:5.x-2.6» 6.x-3.x-dev

This is definitely on the docket for the 3.0 version of the module, but it won't be making it into the current releases (or to Drupal 5).

#12

quicksketch - June 16, 2009 - 16:30
Assigned to:Anonymous» quicksketch

I'm working on implementing this again now that #492806: Separate Webform Configuration from node/edit/x Form is in place. I really can't add this patch as-is because the inconsistencies in handling e-mail doesn't fit with the existing UIs. Instead I'm looking at removing all the e-mail settings entirely from the current location, and place all the e-mail settings in a separate tab with this templating ability.

#13

okmi - June 17, 2009 - 15:20

excellent - thank you very much!

#14

mlaw - June 17, 2009 - 20:30

This is much needed. Subscribing.

#15

quicksketch - June 17, 2009 - 22:54

Alright, well here's the first take at this. I'm pressing forward in an attempt to get to Form Builder functionality and trying to clear out all the blocking/large issues that need to be accounted for first. So I've already committed this patch to the 3.x version (HEAD in CVS). Please update with any problems caused by these changes. For more feature requests expanding on this functionality, PLEASE open a new issue.

Changes:
- New e-mail tab for configuration of e-mails, split off from main webform configuration.
- Death of "Conditional e-mail" configuration, since you can just add a complete webform mailing setting for each component
- Ability to customize the default template (currently there is no ability to save or reuse templates)

Some pics:
skitched-20090617-160301.png

skitched-20090617-160143.png
Uploaded with plasq's Skitch!

Obligitory warning: This patch will make permanent changes to your database making it impossible to go back to the 2.x version of Webform. The Webform 3.x is not yet suitable for use on a live site.

AttachmentSize
webform_email_templates.patch 67.1 KB

#16

quicksketch - June 17, 2009 - 23:00
Status:needs work» fixed

A note on template tokens: I also introduced two tokens for %label[form_key]" and %value[form_key]. This has some drawbacks that Webform does not enforce unique form keys (such as when you clone a fieldset that contains other fields). There's also an existing token for %cid[cid], but I don't like the name of this token and it only gets the value of the field, when really we'd need the label and the value. If anyone has better suggestions for token names, I'm interested. (But let's keep this separate from #428982: Use token.module for token replacement).

#17

quicksketch - June 17, 2009 - 23:20

Here's another patch to fix some lingering cleanup.

AttachmentSize
webform_email_templates_followup.patch 4.87 KB

#18

System Message - July 1, 2009 - 23:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#19

mediamash - October 13, 2009 - 13:29

nice, does this work on drupal6?

#20

doublejosh - November 20, 2009 - 01:59

subscribing

#21

stabilo66 - November 24, 2009 - 02:35

Awesome work thank you, its working like a charm. ;)

 
 

Drupal is a registered trademark of Dries Buytaert.