dongxianshuai8927 2018-05-11 21:38
浏览 97

Laravel 5.6中的计划任务(发送邮件)未执行

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?

  • 写回答

1条回答 默认 最新

  • dprlv04662 2018-05-11 22:01
    关注

    I finally found out why : the time asked in dailyAt('20:00') is 2 hours in the future relative to the server's time.

    To get it to work perfectly, I had to set the dailyAt to 18:00.

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?