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

Gabotronix's avatar

Problem with sending mail after changing to markdown

Hi, I finally got sending mails to work but after noticing how wonky the emails look after being sent I decide to go for markdown emails, I created my markdown mail via cli like this:

php artisan make:mail SimpleContactMail --markdown=emails.simple_contact

However I'm getting the following error:

{message: "Class 'App\Http\Controllers\SimpleContactMail' not found", exception: "Symfony\Component\Debug\Exception\FatalThrowableError", file: "C:\xampp\htdocs\Restaurante1\app\Http\Controllers\ContactController.php", line: 43, trace: Array(55)}

However this doesn't make any sense since the mail class I create exists, it's SimpleContactMail inside app/Mail

Here it is:

<?php

namespace App\Mail;

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

class SimpleContactMail extends Mailable
{
    use Queueable, SerializesModels;
    
    protected $mailData;

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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()

    {
        
        $sender_mail = config('globals.admin_mail');
        
        $restaurant = config('globals.web_name');
        
        $subject="Opinion anonima de $restaurant";
        
        return $this->markdown('emails.simple_contact')->from($sender_mail, 'ReseñasMálaga')->subject($subject);
    }
}


Here is the controller function where I send the mail:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\ContactMail;
use Mail;
use Config;
use Validator;
use Log;

class ContactController extends Controller
{
   


    public function contactar(ContactMail $request)
    {
        //\Log::debug(__METHOD__, $request->all());
        //Log::debug($sender_mail);
        
        $destination_mail = config('globals.client_mail');
        /*
        $sender_mail = config('globals.admin_mail');
        
        $restaurant = config('globals.web_name');
        
        $subject="Opinion anonima de $restaurant";
        
        $message_body = $request->message_body;
        
        Log::debug($subject);*/
        
        $mailData = [];
        
        $message_body = $request->message_body;
        
        $restaurant = config('globals.web_name');
        
        array_push($mailData, $message_body, $restaurant);
        
        
        Mail::to($destination_mail)->send(new SimpleContactMail($mailData));
        
        
        /*Mail::send('emails.simple_contact', ['content' => $message_body], function ($message) use ($sender_mail, $destination_mail, $subject)
        {

        $message->from($sender_mail, 'ReseñasMálaga');

        $message->to($destination_mail);
            
        $message->subject($subject);

        });*/
        
        return response()->json(['success'=>'Mensaje enviado']);
    }
    
    
    
    
    
}


Any idea what could I be doing wrong, this is driving me crazy

0 likes
1 reply
Nash's avatar
Nash
Best Answer
Level 20

Add this to the top of your controller:

use App\Mail\SimpleContactMail;

Please or to participate in this conversation.