Hello Everybody,

To my mind it makes sense to let a custom module a chance to alter list of webform emails, as it will let to take emails depending on form fields values.

For instance:

A webform has a country dropdown and we would like to send a submission to the email address which depends on the selected country.

I propose to add this possibilty after

  // Get the list of e-mails we'll be sending.
  $emails = isset($emails) ? $emails : $node->webform['emails'];

line of webform_submission_send_mail function

Comments

Esculap’s picture

Title: Possibility to alter E-mail to list before sending a sumbission » Possibility to alter E-mail to list before sending a submission
Issue summary: View changes
sunshinee’s picture

Hi, I can't speak to additions to the module, but are you aware you can use the [key] value in a select component to set an email address like:

myemail1@domain.com|Country1
myemail2@domain.com|Country2

...and so forth?

Also, it is possible to accomplish this using the Rules module or Webform hooks-- mymodule_webform_submission_presave() or mymodule_webform_submission_insert() should both be able to modify or send to additional emails.

Hope this helps!
Joy

Esculap’s picture

Hi. Thank you for your quick response. The issue can be closed

DanChadwick’s picture

Status: Active » Closed (works as designed)
Turek’s picture

Well exposing your email addresses as proposed in #2 isn't that good, as spam bots of all kinds would grab those emails easily and start spamming. And sometimes people just don't want to unveil their emails.

I came across similar situation that we have a dropdown of departments where email should go, but this is also dependent on the language user is using. So the same option in the dropdown could go to different email based on the language.

Tried adding email field to the form, and then setting up form to send to that email, but there is no hook where I could populate that field dynamically after submitting the form.

Such hook would be useful to have.

Turek’s picture

Status: Closed (works as designed) » Active
Turek’s picture

Ignore my previous post, was able to sort it out this way :-)

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if (strpos($form_id, 'webform_client_form_') !== FALSE) {
    // Add custom submit handler to webform form.
    $form['#submit'][] = 'MYMODULE_form_submit';
  }
}

function MYMODULE_form_submit($form, &$form_state) {
  dsm($form['#node']->webform['emails']);
}
DanChadwick’s picture

Status: Active » Closed (works as designed)