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

MattB's avatar
Level 2

Mail not finding Mail Class

Ok so I'm trying to send a mail with this controller but when I hit send on the form to call the controller I get a message saying the ContactUs class is not found, even though ContactUs.php is indeed in App\Mail

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Mail\ContactUs;
use Illuminate\Support\Facades\Mail;


class ContactUSController extends Controller
{
    public function contactUSPost(Request $request)
    {
        $data = request()->validate([
            'name' => 'required',
            'email' => 'required|email',
            'number' => 'required',
            'message' => 'required'
        ]);
        Mail::to('[email protected]')->send(new ContactUS($data));
        return back()->with('complete', 'Thanks for contacting us!');
    }
}

Have I made an obvious mistake here?

0 likes
9 replies
cometads's avatar

Mail facade is in the global namespace. The call should be:

\Mail::to('[email protected]')->send(new ContactUS($data));

or add use Mail;

MattB's avatar
Level 2

Tried that but it didn't work. Same error

cometads's avatar

Oh. You capitalized the S in Us.

\Mail::to('[email protected]')->send(new ContactUs($data));

If that doesn't fix it please provide the source of ContactUs.

MattB's avatar
Level 2

Still no joy. My ide is saying App\Mail\ContactUs and Mail are undefined classes. Here's the contents of ContactUs:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class ContactMail extends Mailable
{
    use Queueable, SerializesModels;
    public $data;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.contactForm');
    }
}
Sti3bas's avatar

So your class is named ContactMail, but you're calling it ContactUsin the controller.

cometads's avatar
cometads
Best Answer
Level 3
class ContactMail extends Mailable
{

Your class is defined as ContactMail, not ContactUs. Change it to ContactUs.

MattB's avatar
Level 2

Oh for... Sorry yeah, blind. Wasted your time really....

cometads's avatar

No worries. We all make mistakes like that. Better to ask for help then bang your head against a wall for hours trying to figure it out.

janosk's avatar

Hi there! Are you sure this is the same file? This is a ContactMail class, previously you mentioned ContactUs. (just to be sure we are on the same page)

Edit: posted right after the above comments, i see it is now solved.

Please or to participate in this conversation.