I have used the Mass Contact module to create a contact form that sends mass emails to users based on their role.

This module creates categories that corresponds to roles. For example, it creates a list of users who belong to the role "Faculty".
Each user of role "Faculty" belongs to a department.

I want the module to get the department of the logged in user and then, to select the users who belong to the role "Faculty" and to the department of logged in user (e.g. Digital Systems).

I found this function to the plugin mass_contact_role.inc but i don't know how to change it.

 * Retrieves a list of users by roles.
 * Gets the user IDs for all users in all roles included in the category.
 * @param array $recipients
 *   The list of items for this category. For this plugin implementation, it is
 *   an array of role IDs.
 * @return array
 *   The user IDs that are part of specified roles.
function mass_contact_role_recipients($recipients) {
  // Check to see if a role has been selected.
  if (!isset($recipients['mass_contact_role']) || empty($recipients['mass_contact_role'])) {

  $result = array();
  // Select the users.

  if (!empty($recipients['mass_contact_role'][0]) && $recipients['mass_contact_role'][0] == 2) {
    // If the selected role is the authenticated users role, get everyone.
    $query = "SELECT u.uid FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid WHERE status = 1";
    $result = db_query($query)->fetchAllAssoc('uid', PDO::FETCH_ASSOC);
  elseif (!empty($recipients['mass_contact_role'])) {
    // Get the list of users who belong to the current role.
    $query = "SELECT u.uid FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid WHERE ur.rid IN (:ur_rids) AND status = 1";
    $result = db_query($query, array(':ur_rids' => $recipients['mass_contact_role']))->fetchAllAssoc('uid', PDO::FETCH_ASSOC);
  if (empty($result)) {

  // Collect the uids.
  $uids = array();
  foreach ($result as $record) {
    // For each record in the result set, add the user's ID to the array.
    $uids[] = (integer) $record['uid'];

  return $uids;

Any help? Thank you!


markconroy’s picture

You could create some new user roles:


Then set some users to Faculty AND English and other users to Faculty AND Engineering, etc.

Then, you can choose to send to English only or Engineering only.

Might not be the best approach, as you may not want too many roles created.