Send mails to a list of email with queue jobs

Posted 2 years ago by Chiranjeevi

I've an application, in this I've to send a mail to a list of users. so I'm using queues for this as

$lists = ListUsers::where('list_id',$request->list_id)->pluck('email')->toArray();
            $jobs = (new SendEmailToList($lists));
            return 'success'; 

public $lists;
    public function __construct($lists)
        $this->lists = $lists;
    public function handle()
        $lists = $this->lists;
        foreach ($lists as $key=>$value) {
            Mail::queue('email.test', array('email' => 'Sample'), function ($message) use ($value) {
command= php /var/www/html/project/artisan queue:listen

And I've added a program to "queue:listen" in supervisor of my linux system to run in background as above: I've added all the required functionality for this sending email in queue jobs as given in Laravel Docs, but still it's not working. The requirement is to send mail to list after selecting in a form, but after submitting the details it's taking time to send mails to that list after it's showing success message, but user can't wait until all the mails sent. So it's must show success message directly after submitting form, and it's to be run in background for sending mail using Queue Jobs. Please help me in this, I'm new to laravel. Thank you

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.