Try to use Rules module or Rules API for feature like sending mail based on any event

Problem Statement: Recently, in my project, I came across a situation where on a webform submit by the authenticated user I had to send mail based on a configured variable. So, the condition was if variable is set to value 1 mail should be sent to site admin, else if it is configured 2 mail should be sent to the users which were referenced from the current user via field (say field_user_references) and tricky part if user field (field_user_references) is empty, mail should go to the site admin only.

Now, first obvious, easy and probably perfect solution comes to the mind is custom. Let's make a form alter and add our custom submit handler and play with the code to achieve functionality, quite easy!!!

But, what if we achieve this via Rules module.


Possible Solution: Awesome thing about Drupal is we have 32k+ contrib modules. There is a module Webform Rules which basically will help us to get webform submitted action. Now we want our rules to basically create conditions based on the variables configured. These variables are not directly available in Rules UI for comparison. Again we have a module Token Var which exposes configured variables as token and these tokens can now be used for comparison via Rules UI and in action we can define our send mail action.

Alternative to Token Var: Rules Condition Site Variable

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.