I try to send an email to my users who has unread items, once a day. For that, using Laravel 5.6, I'm scheduling a closure as follow:
use DB;
use Mail;
use App\Mail\UnreadLinks;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function() {
$unreadLinks = DB::table('links')
->leftJoin('users', 'users.id', '=', 'links.recipient_id')
->select('users.email')
->where('links.read_at', null)
->groupBy('users.email')
->get();
foreach ($unreadLinks as $unreadLink) {
Mail::to($unreadLink->email)->send(new UnreadLinks());
}
})->dailyAt('20:00');
}
}
The problem is I do not receive any email.
- The query works well when debugged
- The mail is successfully sent when tried locally with Mailtrap
- Mailgun is correctly set up and works well with other parts of my app
- I set up the cron on my server following the Laravel documentation, and other jobs for other websites are running well
- I do not have any error log written (neither in file on server, nor by email with the
emailOutputTo
method)
Do I miss something here?