2

Is it possible send webform data in email to all users of a specific role?

In the webform email settings there is no such option.

I also tried with Rules, but in rules the webform tokens are rendering the webform submitted data.

Here is my rule attached.

{ "rules_send_email_to_ce_user_on_webform_submit" : {
    "LABEL" : "Send email to CE user on webform submit",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "webform_rules" ],
    "ON" : { "webform_rules_submit" : [] },
    "IF" : [
      { "webform_has_id" : {
          "form_id" : "[form-id:value]",
          "selected_webform" : { "value" : { "webform-client-form-121" : "webform-client-form-121" } }
        }
      }
    ],
    "DO" : [
      { "webform_submissions_load" : {
          "USING" : { "nid" : "121", "sid" : [ "data:sid" ] },
          "PROVIDE" : { "submissions" : { "submissions" : "Fetched submissions" } }
        }
      },
      { "mail_to_users_of_role" : {
          "roles" : { "value" : { "11" : "11" } },
          "subject" : "Form submission from: [node:title]",
          "message" : "DATA\r\n[data:data]\r\n\r\nRAW\r\n[data:data-raw]\r\n\r\nField value\r\n[data:title-value]"
        }
      }
    ]
  }
}

Any other method?

2 Answers 2

1

From the exported rule in your question, it seems you already have the Webform Rules module enabled (a prereq for what follows ...).

You may want to give it a try to process the results of a VBO enabled view via Rules, whereas your rule performs 2 Rules Actions:

  • Load the VBO list that you want to be processed.
  • Add a loop to perform a Rules Action, for each row contained in your Views results.

Some more details about the VBO-view you'd have to create for this:

  1. Create a list users, using the Views module.
  2. It should include an appropriate filter for the role to be processed.
  3. It should have exactly 1 result (row) for each user to be eMailed.
  4. One of the columns should be the eMail Id (I don't see other columns needed for this to work).

For more details, have a look at the tutorial "How to process the results of a VBO enabled view via Rules?".

2
  • VBO is for views, But I'm using any views here.
    – Ahmad
    Commented Feb 15, 2017 at 13:50
  • @Ahmad If you don't have a view "yet", just create one (cfr. the bullet "1." I added to my answer. Commented Feb 15, 2017 at 13:58
1

You can add an additional submit handler for the webform in hook_form_alter. Then in the submit handler, you get the list of users with that role. You can try the below code to get list of users. Then send email to these users with the submitted data.

// get role data by role name
$role_data = user_role_load_by_name('member');

// get list of users with specific role
$uids = db_select('users_roles', 'ur')
->fields('ur', array('uid'))
->condition('rid', $role_data->rid, '=')
->execute()
->fetchCol();

$users_list = user_load_multiple($uids);

There may be better solutions for this. But you can have a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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