Drupal get site wide email address?
Asked Answered
W

5

30

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?

Worthless answered 9/8, 2010 at 18:33 Comment(0)
O
47

Drupal 7

$site_email = variable_get('site_mail', '[email protected]');

Drupal 8+

$site_mail = \Drupal::config('system.site')->get('mail');
Oleg answered 9/8, 2010 at 18:41 Comment(0)
M
27

In Drupal 8:

$site_mail = \Drupal::config('system.site')->get('mail');
Marine answered 4/12, 2015 at 17:8 Comment(0)
F
17

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

variable_get('site_mail', ini_get('sendmail_from'));
Fregger answered 9/8, 2010 at 18:49 Comment(0)
H
3

You can get more ideas with this link

variable_get('site_mail', ini_get('sendmail_from'));
Hairraising answered 9/5, 2013 at 12:19 Comment(0)
M
0

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.

Masson answered 28/2, 2019 at 5:24 Comment(1)
It's much better to use the Drupal 8+ method of service injection than to do this.Lancelancelet

© 2022 - 2024 — McMap. All rights reserved.