Drupal get site wide email address?

2019-04-03 05:09发布

问题:

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?

回答1:

$site_email = variable_get('site_mail', '');


回答2:

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

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


回答3:

In Drupal 8:

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


回答4:

You can get more ideas with this link

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


回答5:

You can preprocess the variable like -

function moi_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.



标签: email drupal