Drupal - How do I allow regular non-admin users to view other users' emails?

One route you can take is to allow users the View user information permission and display this information on the user profile page.

To do so, override user.html.twig in your theme (copy it from core/modules/user/templates/user.html.twig to your theme's template directory) then inject the email into the template via hook_preprocess_user() in your mytheme.theme file:

/**
 * Implements hook_preprocess_user()
 */
function mytheme_preprocess_user(&$variables) {
  $variables['mail'] = $variables['user']->getEmail();
}

In this example, you'll be able to user {{ mail }} to insert the email variable into your user profile template.

Tags:

Users

8

Emails