title: Laravel - changing email settings on the fly is not working
body: <p>All of my email settings for my app are stored in the database.  The user has the option to change those settings, and it all works great.  But I am trying to setup a "Send Test Email" function to allow users to test their settings before saving them.  When they submit the form for to send the test email, the email is sent via the original settings rather than the new settings.</p>
  
  <p>The form is submitted to SettingsController.php</p>
  
  <pre><code>//  Send a test email
  public function sendTestEmail(Request $request)
  {
     Log::info(config('mail.host'));  
     //  Just to check the current email host - shows the proper host 
     //  from the database - i.e. smtp.mailtrap.io
  
     //  Make sure that all of the information properly validates
     $request-&gt;validate([
         'host'       =&gt; 'required',
         'port'       =&gt; 'required|numeric',
         'encryption' =&gt; 'required',
         'username'   =&gt; 'required'
     ]);
  
     //  Temporarily set the email settings
     config([
         'mail.host'       =&gt; $request-&gt;host,
         'mail.port'       =&gt; $request-&gt;port,
         'mail.encryption' =&gt; $request-&gt;encryption,
         'mail.username'   =&gt; $request-&gt;username,
     ]);
     //  Only update the password if it has been changed
     if(!empty($request-&gt;password))
     {
         config(['mail.password' =&gt; $request-&gt;password]);
     }
  
     //  Try and send the test email
     try
     {
         Log::info(config('mail.host'));
         //  Just to check the new setting - this also shows the correct
         //  email host - which is the newly assigned one via the form 
         //  i.e. smtp.google.com
  
         Mail::to(Auth::user()-&gt;email)-&gt;send(new TestEmail());
         return response()-&gt;json([
             'success' =&gt; true,
             'sentTo'  =&gt; Auth::user()-&gt;email
         ]);
     }
     catch(Exception $e)
     {
         Log::notice('Test Email Failed.  Message: '.$e);
         $msg = '['.$e-&gt;getCode().'] "'.$e-&gt;getMessage().'" on line '.
              $e-&gt;getTrace()[0]['line'].' of file '.$e-&gt;getTrace()[0]['file'];
         return response()-&gt;json(['message' =&gt; $msg]);
     }
  }
  </code></pre>
  
  <p>In my TestEmail class, I have brought it down to the basics</p>
  
  <pre><code>namespace App\Mail;
  
  //use Illuminate\Bus\Queueable;  //  Commented out to be sure it is not queuing
  use Illuminate\Mail\Mailable;
  use Illuminate\Queue\SerializesModels;
  //use Illuminate\Contracts\Queue\ShouldQueue;  //  Commented out to be sure it is not queuing
  
  class TestEmail extends Mailable
  {
  //    use Queueable, SerializesModels;  //  Commented out to be sure it is not queuing
  
   /**
   * Create a new message instance.
   *
   * @return void
   */
  public function __construct()
  {
      //
  }
  
  /**
   * Build the message.
   *
   * @return $this
   */
  public function build()
  {
      return $this-&gt;subject('Test Email From '.config('app.name'))-&gt;markdown('email.testEmail');
  }
  }
  </code></pre>
  
  <p>Even though the logs are showing the updated smtp host for the config setting, the message is still being sent out via the original setting - i.e. smtp.mailtrap.io.</p>