title: Laravel "universal to" in development vs production
body: <p>I'm working with a Laravel 5.2 application.  In my development and staging environments, I'd like to make use of the "Universal To" mail config option <a href="https://laravel.com/docs/5.2/mail#mail-and-local-development" rel="nofollow noreferrer">described in the docs</a>.  A universal to in development environments ensures all emails go to that address, instead of out to real customers/clients/whatever.</p>
  
  <p>I can't work out how to specify this differently in production though.  In production there should be <strong>no</strong> universal to - emails should go out to real addresses.</p>
  
  <p>The standard approach of using different <code>env()</code> values does not seem to work.  For example:</p>
  
  <p><strong>config/mail.php</strong>:</p>
  
  <pre><code>'to' =&gt; [
      'address'   =&gt; env('UNIVERSAL_TO', false)
  ],
  </code></pre>
  
  <p><strong>development .env</strong>:</p>
  
  <pre><code>UNIVERSAL_TO=my-testing-address@somewhere.com
  </code></pre>
  
  <p>This works fine - all emails go to the specified <code>UNIVERSAL_TO</code>, as expected.  But if I change that to what I will want in production, eg:</p>
  
  <p><strong>production .env</strong></p>
  
  <pre><code>UNIVERSAL_TO=
  </code></pre>
  
  <p>(or <code>=''</code>, or <code>=false</code>, or simply omitting this completely), sending any mail fails with (in <code>storage/laravel.log</code>):</p>
  
  <blockquote>
    <p>local.ERROR: exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.' in path/to/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php:348</p>
  </blockquote>
  
  <p><code>config/mail.php</code> is just returning an array, so I suppose I could instead set it as a variable and then depending on environment append the 'to' to it, like so:</p>
  
  <pre><code>$return = [ ... normal mail config array ... ];
  
  if (!\App::environment('production')) {
      $return['to'] =&gt; [
          'address' =&gt; 'my-testing-address@somewhere.com'
      ];
  }
  
  return $return;
  </code></pre>
  
  <p>But this seems a little ... hacky.  Is there a better way?</p>