Posted inTechnology / Laravel / php

Only mailables may be queued

Today, We want to share with you Only mailables may be queued.In this post we will show you Sending queued mail with Laravel, hear for Queuing Mailables with Custom Headers in Laravel 5.8 we will give you demo and example for implement.In this post, we will learn about [solved]InvalidArgumentException: Only mailables may be queued with an example.

Only mailables may be queued

There are the Following The simple About Only mailables may be queued Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel send mail without mailable, so the laravel 5.8 only mailables may be queued for this example is following below.

laravel – Mail::queue not working[“solution”]

  • “Only mailables may be queued.”
  • Mail::queue not working
  • how to schedule email queue laravel 5.6
  • Laravel 5.4 Error : Only mailables may be queued
sudo apt-get install apache2 php artisan queue:work

in the main root folder set the .eve file.

QUEUE_DRIVER=database

after that in the simple update queue.php configuration

'default' => env('QUEUE_DRIVER', 'database'),
'database' => [
    'driver' => 'database',
    'table' => 'jobs',
    'queue' => 'default',
    'retry_after' => 90,
],
public function sendMailCustomer($template, $data, $subject, $from_admin = false)
{
    $to = isset($data['to']) ? $data['to'] : [];

    $mail_form_name = isset($data['mail_form_name']) ? $data['mail_form_name'] : '';
    $from_email = isset($data['from_email']) ? $data['from_email'] : '';

    try {
        \Mail::queue($template, $data, function ($message) use ($to, $subject, $from_admin, $mail_form_name, $from_email) {
            $message->from($from_email, $mail_form_name);
            $message->to($to)->subject($subject);
        });

        return ['error' => 0];
    } catch (\Exception $e) {
        dump($e->getMessage());
    }
}
    $mail_data = [
        'to'         => "[email protected]",
        'mail_form_name'  => "This is a tetsing mail For example",
        'from_email' => "jaydeep.pakainfo.com"
        'email_body' => "simple Laravel Queue Job Testing",
    ];
    $this->sendMailCustomer('email.dynamic_email', $mail_data, $template['subject']);

simple Send methods is still working:

Mail::send('email.blank', ['title' => 'Welcome to pakainfo', 'content' => 'message'], function ($message)
        {
            $message->from('[email protected]', 'admin');
            $message->to('[email protected]');
        });

in old version Queue does not work:

Mail::queue('email.blank', ['title' => 'Welcome to pakainfo', 'content' => 'message'], function ($message)
    {
        $message->from('[email protected]', 'jaydeep');
        $message->to('[email protected]');
    });

UPDATE it looks like in laravel 5.6, 5.7 ,5.8 We are only able to simple send and set queue emails using mailables


php artisan make:mail TestMail

within the fresh created the Laravel class change the build function to return an existing simple view e.g

public function build()
    {
        return $this->view('email.test');
    }

then queue the mail to send

 Mail::to('[email protected]')->send(new TestMail());

Answer 1:

the store job tables queue email is use this simple script

Mail::to('[email protected]')->queue(new TestMail());

instead of

Mail::to('[email protected]')->send(new TestMail());// this just commonly sent email not queueing
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Only mailables may be queued.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype