Drupal - get email addresses by role


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function _get_emails_by_role( $role ) {
  2. $q = "SELECT u.mail AS email ";
  3. $q .= "FROM {users} u ";
  4. $q .= "INNER JOIN {users_roles} ur ON u.uid = ur.uid ";
  5. $q .= "INNER JOIN {role} r ON ur.rid = r.rid ";
  6. $q .= "WHERE r.name = '%s';";
  7. $db = db_query($q, $role);
  8. $emails = '';
  9. while ($row = db_fetch_object($db)) {
  10. $emails .= $row->email . ', ';
  11. }
  12. return $emails;
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.