dewesoft's avatar

Mail queue error

When I try to queue mail (Mail::to($to)->bcc($bcc)->queue(new GenericMail($subject, $content));) I receive this error:

PHP Fatal error: Illuminate\Mail\SendQueuedMailable::handle(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "App\Mail\GenericMail" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide an autoloader to load the class definition in /Users/jurejager/Code/api.dewesoft/vendor/laravel/framework/src/Illuminate/Mail/SendQueuedMailable.php on line 52

But when I send without adding to the queue (Mail::to($to)->bcc($bcc)->send(new GenericMail($subject, $content));), mail is sent.

My mail class:

<?php

namespace App\Mail;

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

class GenericMail extends Mailable
{
    public $content;
    public $subject;

    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @param $subject
     * @param $content
     */
    public function __construct($subject, $content)
    {
        $this->subject = $subject;
        $this->content = $content;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject($this->subject)->view('mails.generic-template');
    }
}

Did anyone had the same problem?

Thanks

0 likes
3 replies
ts's avatar
ts
Best Answer
Level 6

Strange. All looks fine to me. Try running composer dump-autoload in the terminal.

2 likes
dewesoft's avatar

Actually that was it! I don't know why I haven't tried that before.

Thank you!

njoguamos's avatar

I had this problem. I had two Laravel applications sharing the same Redis instance in production.

I solved it by setting a unique' REDIS_PREFIX` for each application.

Please or to participate in this conversation.