2

Can anyone help with some tips on how to queue email using an OctoberCMS ajax page?

 function sendRecipientMsg($dataset, $sendCounter, $recipients){
    $template = $dataset['template'];
    Mail::queue($template, $dataset, function($message) use($dataset, $recipients){
        $message->to('piggy@teamprema.co.nz','MissPiggy');
        $message->subject('Have a good day');    
        $message->from('us@prema.co.nz',  'Mike and Stephie');
        $message->sender('us@prema.co.nz',  'Mike and Stephie');

        trace_log('$message');
        $message->cc($address, $name = null);
        $message->bcc('systems@safe.org.nz', 'SAFE Campaigns Feedlots ECards');
    });
 }

This code works when we use Mail::send but not with Mail::queue

Any help or tips very welcome

Josef Kufner
  • 2,851
  • 22
  • 28
Cloudworks
  • 129
  • 7

1 Answers1

2

In your config/queue.php file, which driver do you have set as the default?

For example: 'default' => env('QUEUE_DRIVER', 'sync')

(if you are using DotEnv then check the .env file in your docroot).

If you are using sync, it should send right away as sync is really only for development and will still block.

If you are using another method, like database, then you do have to ensure that your queues are configured to process how you expect.

Try running php artisan queue:work, then trigger your ajax call and it should send.

Joseph Oppegaard
  • 611
  • 5
  • 12
  • Thanks Joseph. Huge help. We've got as far as the job table but the job table isn't loading at this point. Going to look over our code. Thanks for some key information – Cloudworks Sep 28 '18 at 00:48