I'm trying to create an environment variable for email settings, but it doesn't work. Here is my email setting at config/general.php

'dev' => [
    '@host' => 'host',
    '@port' => '587',
    '@username' => 'user@user',
    '@password' => 'passwrod'

This is my email setting

I have also tried before to configure the email setting using this way at config/app.php, but it doesn't work.

'components' => [
    'mailer' => function() {
        // Get the stored email settings
        $settings = Craft::$app->systemSettings->getEmailSettings();

        // Override the transport adapter class
        $settings->transportType = \craft\mail\transportadapters\Smtp::class;

        // Override the transport adapter settings
        $settings->transportSettings = [
            'host' => 'host',
            'port' => '587',
            'useAuthentication' => true,
            'username' => 'user@user',
            'password' => 'passwrod'

        return craft\helpers\MailerHelper::createMailer($settings);

Am I doing anything wrong?

1 Answer 1


I think you're getting a few conventions mixed up.

Using an @ is typically reserved for aliases https://docs.craftcms.com/v3/config/environments.html#using-aliases-in-control-panel-settings

What you're probably looking for is environment variables in your .env file.

You could set:


Then from Settings->Email in the control panel, you can reference them with $ https://docs.craftcms.com/v3/config/environments.html#control-panel-settings


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.