I've built a form at http://dev.vies.dk/tilmelding. In the backend, it is easy to send e-mails to people filling out the form.

However, I need to send additional e-mails to other people based on some of the answers in the webform, namely the subjects they choose and the sex they have.

Subject         Female       Male
Soccer          mail@mail.dk mail@mail.dk
Handball        my@mail.dk   your@mail.dk
Kayak           mail@mail.dk mail@mail.dk
Dance           be@mail.dk   eb@mail.dk
Biking          sv@mail.dk   ls@mail.dk

Is there a hook, where this can be programmed, so I can achieve what I want?


Yes, you want to use hook_mail_alter() in a custom module. This will intercept the outgoing email from Drupal and allow you to add programming logic to the process. For example you could:

  • Load the webform in question and view its results.
  • alter the to value of the $message to meet your needs.

'to': The address or addresses the message will be sent to. The formatting of this string will be validated with the PHP e-mail validation filter.

  • How would you load the webform, because when I grasp that, I think I might be good to go? Nov 6 '13 at 19:41
  • You probably dont want the webform itself, you want the submission by a given user. You want to look at the webform API, and at least the function webform_get_submissions. Also if you simply do a node_load() on a NID with a webform -- you get the webform itself back as apart of the Node.
    – tenken
    Nov 6 '13 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.