title: sending mail in Laravel 5.4 using Mailgun get error code " 401 UNAUTHORIZED` response: Forbidden "
body: <p>I'm trying to send mail in Laravel 5.4 project with Mailgun. I think I set the configuration correctly. But, I got this error message such as </p>
  
  <blockquote>
    <p>ClientException in RequestException.php line 111:
    Client error: <code>POST https://api.mailgun.net/v3/sandboxfeb88d58f18841738b2fc81d7cbc7631.mailgun.org/messages.mime</code> >resulted in a <code>401 UNAUTHORIZED</code> response:
    Forbidden</p>
  </blockquote>
  
  <p>Here is my configuration:</p>
  
  <p>in .env file</p>
  
  <pre><code>MAIL_DRIVER=mailgun
  MAILGUN_DOMAIN=sandboxfeb88d58f18841738b2fc81d7cbc7631.mailgun.org
  MAILGUN_SECRET=pubkey-1767e**********
  </code></pre>
  
  <p>in mail.php file</p>
  
  <pre><code>'driver' =&gt; env('MAIL_DRIVER', 'smtp'),
  'host' =&gt; env('MAIL_HOST', 'smtp.mailgun.org'),
  'port' =&gt; env('MAIL_PORT', 587),
  'from' =&gt; [
      'address' =&gt; env('MAIL_FROM_ADDRESS', 'richi.htoo@gmail.com'),
      'name' =&gt; env('MAIL_FROM_NAME', 'Richi Htoo'),
  ],
  </code></pre>
  
  <p>in services.php file</p>
  
  <pre><code>'mailgun' =&gt; [
      'domain' =&gt; env('MAILGUN_DOMAIN'),
      'secret' =&gt; env('MAILGUN_SECRET'),
  ],
  </code></pre>
  
  <p>and I wrote mail sending code in default route such as</p>
  
  <pre><code>Route::get('/', function () {
  //return view('welcome');
  
      $data = [
          'title' =&gt; 'Hi student I hope you like the course',
          'content' =&gt; 'This laravel course was created with a lot of love and dedication for you'
      ];
  
      Mail::send('emails.test', $data, function($message){
          $message-&gt;to('white.nuzzle@gmail.com', 'White Nuzzle')-&gt;subject('Hello student how are you?');
      });
  });
  </code></pre>
  
  <p>And I also installed Laravel Package "guzzlehttp/guzzle" version 6.2 to send mail.</p>
  
  <p>But when I call that default home route, I got an error message as I mention above.</p>
  
  <p>I can't find any solution for my error in any where including this forum "stackoverflow.com".</p>
  
  <p>Can anyone help me please?</p>