-
-
Save verschuur/004c26fe14ba2a43a3c5f422c47c029c to your computer and use it in GitHub Desktop.
Craft 3 multi-env email settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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