Hi, this is what I would like to do, taken from http://drupal.stackexchange.com/questions/5754/webform-send-multiple-email:

I have created a webform. There is one field "Send invitation to your friends" . In this field user can enter their friends email ids (Comma seperated) For example A@gmail.com,B@yahoo.com,C@hotmail.com etc. I want to send a common email "Welcome and join us" to all these people. Can anyone help me, how can I proceed?

And here are a few hurdles I am finding:

1. To send to an email a field must be of type "email", however the markup that is generated does not have the "multiple" option applied, so modern browsers will invalidate anything separated by commas, such as "A@gmail.com,B@yahoo.com,C@hotmail.com". Therefore a "multiple" checkbox would need to be added to the email component creation form that would add this attribute to the form element when checked.

2. The email component validation function does not expect emails to be separated by commas and checks the value against Drupal's validate_email function with the whole value of the field:

function _webform_validate_email($form_element, &$form_state) {
  $component = $form_element['#webform_component'];
  $value = trim($form_element['#value']);
  if ($value !== '' && !valid_email_address($value)) {
    form_error($form_element, t('%value is not a valid email address.', array('%value' => $value)));
  }
  else {
    form_set_value($form_element, $value, $form_state);
  }
}

This function would need to check if the multiple flag is set to true on the form_element and validate accordingly (separate by delimiter, trim and validate each item separately).

3. I tried using a regular text field and token value [submission:values:emails_to_share_with] in the "Custom" box when setting up an Email item, but it also tried to validate assuming an email value or a separation of email values, giving the error:

The entered e-mail address "[submission:values:emails_to_share_with]" does not appear valid.

so this is not a viable workaround.

Is this a feature that exists, or is there a known workaround? I have searched but found nothing quite fitting the requirements. If it is not a feature and it seems like something that would be useful, I wouldn't mind helping to develop a patch for it if it would be helpful?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ransomec’s picture

Issue summary: View changes

Corrected token used in item #3

ransomec’s picture

Issue summary: View changes

Want to note I looked at invite and forward modules as well and neither address the level of customization my client needs.

edit: Also felt "take responsibility" in that last sentence came on a bit strong, as I'm not sure how you prefer to maintain the project. I am just offering to help if it would be helpful :)

ransomec’s picture

Version: 7.x-4.x-dev » 7.x-3.x-dev
quicksketch’s picture

The entered e-mail address "[submission:values:emails_to_share_with]" does not appear valid.

If you're using this style of tokens, it would appear that you're running Webform 7.x-4.x, as it's the only one that supports this style.

Webform actually specifically prevents sending multiple e-mails with values provided by end-users to help prevent the form from being used for spamming purposes. Having this as an option sounds like a possibility, but I'm not sure what kinds of problems we may be creating for ourselves by having this feature.

ransomec’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev

Thank you for the reply quicksketch, and you are correct, it is the 7.x-4.x branch, I have updated the ticket to reflect it. I apologize for the mislead.

Hm, I can see how this would be a worry, and may have been brought up by my client in time, so good to bring it up early. I can think of two ways to limit this while still giving the client the ability to create such a field: 1. Limit the size of the entry box and 2. using flood control to ensure a user can't submit the form rapidly.

If it is deemed a dangerous feature I understand, I will simply have to find workarounds. Thanks!

DanChadwick’s picture

Status: Active » Fixed
FileSize
7.34 KB

This patch adds the following to email components:

1) The ability to configure an email component to support more than one e-mail address, separated by a comma and optional spaces.
2) The ability to configure e-mail components to support long-format e-mail addresses (e.g. "Some Name" ").
3) html5 in-browser validation for multiple addresses.
4) html5 in-browser validation for long-format e-mail addresses by text patterns, since html5 does not support long format e-mail addresses.

Committed to 7.x-4.x and 8.x.

  • DanChadwick committed 5f18ac1 on 8.x-4.x
    Issue #2200587 by DanChadwick: Added multiple e-mail addresses and long-...

Status: Fixed » Closed (fixed)

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