28
votes

In my module I want to get the site wide email address - the one that is set in the site information admin pages and that is used for all automatically send email messages.

How can I do this?

5

5 Answers

44
votes
$site_email = variable_get('site_mail', '');
20
votes

In Drupal 8:

$site_mail = \Drupal::config('system.site')->get('mail');
16
votes

Looking into the system module, I found the settings form references the following:

variable_get('site_mail', ini_get('sendmail_from'));
2
votes

You can get more ideas with this link

variable_get('site_mail', ini_get('sendmail_from'));
0
votes

You can preprocess the variable like -

function hook_preprocess(&$variables, $hook) {

  $variables['site_email'] =  \Drupal::config('system.site')->get('mail');
  //kint( $variables['site_email']);

}

then use $variables['site_email'] anywhere to get the system wide email.