Skip to content

Instantly share code, notes, and snippets.

@mmikkel
Created August 19, 2018 13:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmikkel/9cf5de00bff899d4e4134cc0690f360d to your computer and use it in GitHub Desktop.
Save mmikkel/9cf5de00bff899d4e4134cc0690f360d to your computer and use it in GitHub Desktop.
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