maaxim-one's avatar

Laravel 11. An email must have a "To", "Cc", or "Bcc" header. On queue.

Hello!

I have a problem with the mail service. If I send a letter without a queue, everything goes well. I can't figure out what's wrong.

Error: Symfony\Component\Mime\Exception\LogicException: An email must have a "To", "Cc", or "Bcc" header

Mailable file

Controller File

class TeaAndCoffee extends Controller
{
    protected Request $_request;

    public function __construct(Request $request)
    {
        $this->_request = $request;
    }

    public function sendPrice()
    {
        $this->_request->validate([
            'phone' => 'required_without:email|nullable|string',
            'email' => 'required_without:phone|nullable|email',
        ]);

        Mail::send(new TeaAndCoffeePriceMail(
            phone: $this->_request->input('phone'),
            email: $this->_request->input('email')
        ));

        return response()->json(true);
    }
}
0 likes
7 replies
Glukinho's avatar

Maybe rewrite sending in controller to set To address explicitly?

Mail::to('[email protected]')
    ->queue(new TeaAndCoffeePriceMail(
        phone: $this->_request->input('phone'),
        email: $this->_request->input('email')
    )
);
Glukinho's avatar

@maaxim-one Maybe stupid question, have you restarted your queue worker(s) after code changing?

Glukinho's avatar
Glukinho
Best Answer
Level 33

I've tested similar configuration as yours on Laravel 12.12.0, works fine in all cases (To address is set in Envelope class or when sending; mail is queued or not).

Maybe update to latest Laravel 11 or even 12?

maaxim-one's avatar

In general, updating and clearing the cache helped.

Please or to participate in this conversation.