title: How to send emails in Laravel according to app environment?
body: <p>I have several controllers that send emails, all of them uses <code>Illuminate\Mail</code>, which provides an event called <code>Illuminate\Mail\Events\MessageSending</code> that triggers when a message is being sent. </p>
  
  <p>I would like to intercept the message at that point and change the <code>$to</code> variable, replacing whatever value is there with a developer email, depending on the <code>\App::environment()</code> value.</p>
  
  <p>I added a listener in the <code>EventServiceProvider</code>, receiving an instance of <code>MessageSending</code>, which passes <code>\Swift_Message $event</code> as parameter to listener's <code>handle()</code> method.</p>
  
  <p>However, I'm stuck here. Here's what I did:</p>
  
  <pre><code>    // dd()'s are removed in final code, they are here just as examples
  
      // array with real emails
      dd($event-&gt;message-&gt;getTo());
  
      if (!\App::environment('production')) {
          $event-&gt;message-&gt;SetTo(['developer@test.com']);
      }
  
      // developer@test.com
      dd($event-&gt;message-&gt;getTo());
  
      return $event;
  </code></pre>
  
  <p>It changes $event, but it doesn't seem to make a difference.</p>
  
  <p>What I'm doing wrong?</p>