1

I'm trying to set this up changing config/app.php

with


'dev' => [
        'components' => [
            'mailer' => function () {
                // Get the stored email settings
                $settings = App::mailSettings();

                // Override the transport adapter class
                $settings->transportType = Smtp::class;

                // Override the transport adapter settings
                $settings->transportSettings = [
                    'host' => getenv('SMTP_HOSTNAME'),
                    'port' => getenv('SMTP_PORT'),
                    'useAuthentication' => (bool)getenv('SMTP_USE_AUTH') ?: true,
                    'username' => getenv('SMTP_USERNAME'),
                    'password' => getenv('SMTP_PASSWORD'),
                    'encryptionMethod' => getenv('SMTP_ENCRYPTION_METHOD') ?: null, // 'ssl' or 'tls' or nothing
                    'timeout' => getenv('SMTP_TIMEOUT') ?: 10,
                ];

                // Create a Mailer component config with these settings
                $config = App::mailerConfig($settings);

                // Instantiate and return it
                return Craft::createObject($config);
            },
        ],
    ],

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

                // Override the transport adapter class
                $settings->transportType = MailgunAdapter::class;

                // Override the transport adapter settings
                $settings->transportSettings = [
                    'domain' => App::env('CRAFT_MAILGUN_DOMAIN'),
                    'apiKey' => App::env('CRAFT_MAILGUN_API_KEY'),
                ];

                return MailerHelper::createMailer($settings);
            }
        ]
    ],

The control panel tells me It looks like these settings are being overridden by /Users/steven/Sites/xxx/config/app.php. but when I test the email, it always wants to go out via Mailgun rather than the local mail server configured for dev.

What have I missed here? My env has everything it needs and is in dev mode.

1 Answer 1

3

This caught me out too. It says in the docs that

Any changes you make to the Mailer component from config/app.php will not be reflected when testing email settings from Settings → Email.

Any changes you make to the Mailer component from config/app.php will not be reflected when testing email settings from Settings → Email.

1
  • 🤦🏻‍♂️ good catch...I wasn't even referencing the Craft docs in this instance Commented Mar 3, 2022 at 9:15

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.