Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel send mail using queue() not working on server

I have trying to send mail using Laravel queue job, and my site on hostmonster web server but it is not sending mail when I fire php artisan queue:work, It clears Job table but not mail received to my email address.

Here is my code to queue and send mail function:

    //It is working
    $to = '****@g***l.com';
    \Mail::to($to)->send(new ContactUsMail($contactUsId));

    //It is not working: on same host email working not work with hotmail - gmail - other
    $to = '****@g***l.com';
    \Mail::to($to)->queue(new ContactUsMail($contactUsId));

The mail send working fine with 2 case:

  1. If I send mail using send() method (bypass/ignore queue)
  2. also using queue() send to same hosting email (like [email protected])

But now if I use [email protected]/[email protected] then in such case queue not working - job table also delete entry as mail sent but bingo..!! where mail send I don't know.

Also cron mail same problem as queue simple mail() function working there not Mail::send() work there..!

like image 609
bharat Avatar asked Mar 07 '23 06:03

bharat


2 Answers

After many tries I have found solution with my server that is below setting working fine :

.env file setup MAIL_DRIVER=sendmail.

config/mail.php file 'sendmail' => '/usr/sbin/sendmail -t' replace -bs with -t.

like image 184
bharat Avatar answered Mar 15 '23 17:03

bharat


  1. You need to execute the queue worker php artisan queue:work.
  2. change QUEUE_DRIVER=sync to QUEUE_DRIVER=redis or QUEUE_DRIVER=database
like image 29
sumit sharma Avatar answered Mar 15 '23 18:03

sumit sharma