Tamer Zoubi @ Drupal 8


Drupal expert | Programmer

mail

How to retrieve site wide email address in Drupal 8

In Drupal 7 you would easily retrieve site wide email address through variable:

<?php 
$site_email = variable_get('site_mail', '');
?>

However in Drupal 8 variables are gone in favor of configuration objects. So the same functionality in Drupal 8 would be: 

<?php 
 $system_site_config = \Drupal::config('system.site');
 $site_email = $system_site_config->get('mail');
?>

 

Tags
Drupal 8
config
mail
variable_get