Skip to content

Instantly share code, notes, and snippets.

@verschuur

verschuur/app.php

Forked from mmikkel/app.php
Created Nov 3, 2020
Embed
What would you like to do?
Craft 3 multi-env email settings
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app/main.php and [web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
*
* You can define custom modules and system components, and even override the
* built-in system components.
*/
return [
'modules' => [
'my-module' => \modules\Module::class,
],
//'bootstrap' => ['my-module'],
'*' => [
],
'dev' => [
'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' => 'smtp.mailtrap.io',
'port' => '2525',
'useAuthentication' => true,
'username' => 'USERNAME',
'password' => 'PASSWORD'
];
return craft\helpers\MailerHelper::createMailer($settings);
}
]
],
'staging' => [
'components' => [
'mailer' => function() {
// Get the stored email settings
$settings = Craft::$app->systemSettings->getEmailSettings();
// Override the transport adapter class
$settings->transportType = craft\mailgun\MailgunAdapter::class;
// Override the transport adapter settings
$settings->transportSettings = [
'domain' => 'YYYYYYYYYYYY',
'apiKey' => 'key-YYYYYYYYYYYY',
];
return craft\helpers\MailerHelper::createMailer($settings);
}
]
],
'production' => [
'components' => [
'mailer' => function() {
// Get the stored email settings
$settings = Craft::$app->systemSettings->getEmailSettings();
// Override the transport adapter class
$settings->transportType = craft\mailgun\MailgunAdapter::class;
// Override the transport adapter settings
$settings->transportSettings = [
'domain' => 'ZZZZZZZZZZZZ',
'apiKey' => 'key-ZZZZZZZZZZZZ',
];
return craft\helpers\MailerHelper::createMailer($settings);
}
]
],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment