Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-20T15:16:09.913Z
Answers.LastActivityDate: 2019-03-20T15:16:09.913Z
Answers.UserDisplayName: sunscreem
Body: <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>
  
Tags: <config><multi-environment>
Title: How to do multi-environment app config (config/app.php)?
ThreadText: # 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](https://docs.craftcms.com/v3/configuration.html#application-config). Brandon's Github comment [here](https://github.com/craftcms/cms/issues/1344#issuecomment-277767746) 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.
  
  
  ---
  
  