title: Laravel 9.x After submitting the form Mailgun returns not defined Error. [Email couldn't delivered]
body: <p>Trying to send data with input form. User sends information such as name, email, subject and the message. This form is getting used for reporting issues to do admin. When submit the form, returns Mailgun not defined error.</p>
  <p>new to laravel and mvc.</p>
  <p><a href="https://i.stack.imgur.com/8C3GE.png" rel="nofollow noreferrer">The Error</a></p>
  <p><strong>.env</strong></p>
  <pre><code>MAIL_MAILER=Mailgun
  MAIL_HOST=smtp.mailgun.org
  MAIL_PORT=587 
  MAIL_USERNAME=postmaster@MyUsername.mailgun.org
  MAIL_PASSWORD=myPassword
  </code></pre>
  <p><strong>config/mail.php</strong></p>
  <pre><code>'default' =&gt; env('MAIL_MAILER', 'smtp'),
  
      'mailers' =&gt; [
          'smtp' =&gt; [
              'transport' =&gt; 'smtp',
              'host' =&gt; env('MAIL_HOST', 'smtp.mailgun.org'),
              'port' =&gt; env('MAIL_PORT', 587),
              'encryption' =&gt; env('MAIL_ENCRYPTION', 'tls'),
              'username' =&gt; env('MAIL_USERNAME'),
              'password' =&gt; env('MAIL_PASSWORD'),
              'timeout' =&gt; null,
          ],
          
      ],
  
          'mailgun' =&gt; [
              'transport' =&gt; 'mailgun',
          ],
  
          'failover' =&gt; 
          [
              'transport' =&gt; 'failover',
              'mailers' =&gt; [
                  'smtp',
                  'log',
              ],
          ],
  </code></pre>
  <p><strong>app/Mail/contacter.php</strong></p>
  <pre><code>namespace App\Mail;
  
  use Illuminate\Bus\Queueable;
  use Illuminate\Contracts\Queue\ShouldQueue;
  use Illuminate\Mail\Mailable;
  use Illuminate\Queue\SerializesModels;
  
  class contacter extends Mailable
  {
      use Queueable, SerializesModels;
  
      public $emailData;
    
      public function __construct($emailData)
      {
          $this-&gt;mailData = $emailData;
        
      }
      public function build()
      {
          return $this-&gt;subject('Message')
                      -&gt;view('mail');
      }
  }
  </code></pre>
  <p><strong>ContactUsFormController.php</strong></p>
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use app\Models\Contact;
  use app\Mail\contacter;
  use Illuminate\Support\Facades\Mail;
  
  
  class ContactUsFormController extends Controller
  {
      public function createForm(Request $req){
          return view('contact');
      }
      public function ContactUsForm(Request $req){
                  //form validation 
                  $this-&gt;validate($req,[
                      'name' =&gt; 'required',
                      'email' =&gt; 'required | email',
                      'subject' =&gt; 'required',
                      'message' =&gt; 'required'
                  ]);
                  $email = [
                      'name' =&gt; $req-&gt;get('name'),
                      'email' =&gt; $req-&gt;get('email'),
                      'subject' =&gt; $req-&gt;get('subject'),
                      'message' =&gt; $req-&gt;get('message')
                  ];
  
                Mail::to(env('ADMIN'))-&gt;send(new contacter($email));
  
              return back()-&gt;with('success', 'We have recieved your message and will reply to ' . $email['email'] . ' email address!');
  
  
     }
  }
  </code></pre>
  <p><strong>web.php</strong></p>
  <pre><code>Route::get('/contact', [ContactUsFormController::class, 'createForm']);
  Route::post('/contact', [ContactUsFormController::class, 'ContactUsForm'])-&gt;name('contact.store');
  </code></pre>
  <p><strong>mail.blade</strong></p>
  <pre><code>    &lt;h1&gt;About : {{ $emailData['subject'] }}&lt;/h1&gt;
      &lt;p&gt;From : {{ $emailData['name'] }}&lt;/p&gt;
      &lt;p&gt;Reply To : {{$emailData['email']}}&lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;p&gt;{{$emailData['message']}}&lt;/p&gt;
       
      &lt;br /&gt;
      &lt;p&gt;END&lt;/p&gt;
  </code></pre>