php - Laravel 5.6 中的计划任务(发送邮件)未执行
问题描述
我尝试每天向有未读项目的用户发送一封电子邮件。为此,使用 Laravel 5.6,我安排如下关闭:
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');
}
}
问题是我没有收到任何电子邮件。
- 调试时查询运行良好
- 使用 Mailtrap 在本地尝试时成功发送邮件
- Mailgun 已正确设置并与我的应用程序的其他部分配合良好
- 我按照 Laravel 文档在我的服务器上设置了 cron,其他网站的其他作业运行良好
- 我没有写任何错误日志(既没有在服务器上的文件中,也没有通过电子邮件使用该
emailOutputTo
方法)
我在这里想念什么吗?
解决方案
我终于找到了原因:dailyAt('20:00')
相对于服务器的时间,请求的时间是未来 2 小时。
为了让它完美地工作,我不得不将它设置dailyAt
为18:00。
推荐阅读
- javascript - html 元素不可见。它在那里,但它的尺寸为 0x18
- scala - Spark,如何将 AB,C 转换为 (A, List(B,C))
- r - 如何编写时间循环并给出一个数字
- python - 随机字典选择?
- c - 致命错误:curl/curl.h:没有使用 vcpkg 的文件或目录
- python - 将 PHP POST 请求中的值连接到要执行的 python 脚本中的变量
- java - 没有值的 Java 多键映射
- mysql - 按月选择sql
- php - 如何(通过 Blogger.com)生成一次性动态链接到我的电子书托管@DropBox?
- reactjs - 单击按钮后,如何使用 Reactjs 重定向到带有自动正文和发件人的 Outlook 邮件?