7

From a template or a plugin, how can I get the value of admin/Settings/System Email Address ? Thanks for your help Nicolas

3 Answers 3

13

You can get this in a template like so:

{# returns an array of your email settings #}
{% set settings = craft.systemSettings.email %}

{# returns the email address #}
{{ settings.emailAddress }}

And in a plugin you can do:

craft()->systemSettings->getSetting('email', 'emailAddress')
3

In craft 3 it appears you can access it by doing the following:

{{ craft.systemSettings.email.fromEmail }}

0
3

The craft.systemSettings variable was been deprecated as of Craft 3.1.0, and removed in Craft 4.0.

Here's how to get the system email address in Craft 3.1.0+:

{{ craft.app.projectConfig.get('email').fromEmail }}

Important: If your system email is set to an environment variable (e.g. like $SYSTEM_EMAIL_ADDRESS), you can use the parseEnv() Twig function to render it:

{{ parseEnv(craft.app.projectConfig.get('email').fromEmail) }}

Other email settings such as replyToEmail and fromName are also available via craft.app.projectConfig.get('email'), and can be access and used in the same way as the fromEmail.

Alternatively, email settings can be accessed via the App helper class, although it is generally discouraged to instantiate the App helper class from Twig:

{% set appHelper = create('craft\\helpers\\App') %}
{{ appHelper.mailSettings.fromEmail }}

Or in PHP:

$fromEmail = App::mailSettings()->fromEmail;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.