Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KIEYCH's avatar

Method 'to' not found in \Illuminate\Support\Facades\Mail

Hey guys, I am trying to send an Email, but I'm getting this error: Method 'to' not found in \Illuminate\Support\Facades\Mail

I'm doing this on a laravel command, it's like a cron to send all emails that are queued in a table 'EmailQueue'

I have this on top of the file: use Illuminate\Support\Facades\Mail;

I was reading docs: https://laravel.com/docs/5.4/mail

They say its Mail::to But it doesn't work? What am I missing here? I've got mail.php and .env files configured to send the emails with my gmail account (just for testing for now)

Thanks in advance!

0 likes
10 replies
KIEYCH's avatar

Such a simple thing..but can't find the solution anywhere : /

Parasoul's avatar
Parasoul
Best Answer
Level 3

Hey the facade just give an accessor to the real class. You don't have to include it.

You should have smth like this in your config/app.php

'aliases' = [
    //Other Alias
        'Mail' => Illuminate\Support\Facades\Mail::class,
    //Other Alias
],

It creates an alias for this class \Illuminate\Mail\Mailer; Which you can call this way

use Mail;
1 like
AddWebContribution's avatar

Since it's a facade, just add this to the top of the class:

use Mail;

Or use full namespace when using the facade:

\Mail::send

Hope this help for you !!!

1 like
rizwanjaved's avatar
use Illuminate\Contracts\Mail\Mailer;

 public function addApplicant(Request $request, Mailer $mailer)
    {
  $mailer->send('emails.toApplicant', [
                'applicant'              => $applicant,
                'applicationDetailUrl' => $applicationDetailUrl
            ], function ($m) use ($applicant) {
                $m->to($applicant->email, $applicant->name)->subject('Application Submitted Successfully');
            });
}

or if you want to use Mail, u can importing same facade but using it as :

$data = [
            'key'     => 'value'
        ];
        \Mail::send('login', $data, function ($m) use ($data) {
                $m->to('[email protected]', 'rizwan')->subject('Route test!');
        });
        dd(Mail::failures());
```
KIEYCH's avatar

@Parasoul @saurabhd I do have that: 'aliases' = [ //Other Alias 'Mail' => Illuminate\Support\Facades\Mail::class, //Other Alias ],

on my config/app.php

But when I do this "use Mail;" on top of my Laravel Command, it says "Undefined Mail class"

Does this work on a Laravel Command? Btw I'm trying to send a Mailable

Jaytee's avatar

Try just dumping the autoload composer dump-autoload

Sometimes in fresh applications, some things just dont work for reasons unknown. If your app is new, you can always just create a new app

KIEYCH's avatar

Turns out phpStorm was giving me this error, but it actually works...silly me trusting phpStorm errors...

Please or to participate in this conversation.