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.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序