<p>To get this to work, have a look at the format of the <code>general.php</code> config file. </p>

<p>The key is to include the <code>'*'=&gt;[]</code> at the start.</p>

CC BY-SA 4.0
2019-03-20T15:16:09.913Z
2019-03-20T15:16:09.913Z
sunscreem
<p>I'm trying to setup different mail settings per environment. Here is my mail component that I'm defining in <code>config/app.php</code>:</p>

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

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

        // Override the transport adapter settings
        $settings-&gt;transportSettings = [
            'host'              =&gt; 'localhost',
            'port'              =&gt; '1025',
            'useAuthentication' =&gt; false,
            'encryptionMethod'  =&gt; null,
            'timeout'           =&gt; '10',
        ];

        return craft\helpers\MailerHelper::createMailer($settings);
    },
],
</code></pre>

<p>How do I ensure this only applies to development environments? Multi-environment doesn't seem to work like it does for <code>config/general.php</code> and there's no multi-environment example in the <a href="https://docs.craftcms.com/v3/configuration.html#application-config" rel="nofollow noreferrer">relevant documentation</a>. Brandon's Github comment <a href="https://github.com/craftcms/cms/issues/1344#issuecomment-277767746" rel="nofollow noreferrer">here</a> suggests that this is possible. Thanks.</p>

<config><multi-environment>
How to do multi-environment app config (config/app.php)?
# How to do multi-environment app config (config/app.php)?

(Asked by: username_0 on 2018-06-03)

I'm trying to setup different mail settings per environment. Here is my mail component that I'm defining in config/app.php:
'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'              => 'localhost',
            'port'              => '1025',
            'useAuthentication' => false,
            'encryptionMethod'  => null,
            'timeout'           => '10',
        ];

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

How do I ensure this only applies to development environments? Multi-environment doesn't seem to work like it does for config/general.php and there's no multi-environment example in the relevant documentation. Brandon's Github comment here suggests that this is possible. Thanks.

**Tags:** config, multi-environment

---

## 1 answers

### Answer by username_1 on 2019-03-20. Score: 2

To get this to work, have a look at the format of the `general.php` config file.

The key is to include the `'*'=>[]` at the start.


---

