0

我需要从 laravel 任务发送电子邮件。我有这个任务的代码。

$schedule->call(function () {
  $date = now()->addDays(1);
  echo 'step 1';
  $appointment = Cita::whereDate('date', $date)->with(['patient'])->orderBy('date')->orderBy('hour')->get();
  echo 'step 2';
  foreach($appointment as $appt) {
    $data = array("name" => $appt->patient->name, "body" => 'Remember me');
    if ($appt->patient->email !== null) {
      Mail::to($cita->paciente->email)->send(new Reminder($data));
    }
    echo 'step 3';
   }
 })->everyMinute();

运行命令时

php artisan schedule: run

在终端中手动,一切运行正常,我收到了电子邮件。使用邮件陷阱。

然后我添加这个

* * * * * cd / app && php artisan schedule: run >> /app/log.log 2> & 1

在 crontab 中。

我将命令输出发送到 log.log 文件以便能够查看回声。

并且只能绘制第一个回声(步骤 1),其余的回声不再添加到日志中。

这是日志中显示的结果。

Running scheduled command: Closure
step 1

没有显示错误,也没有向我发送电子邮件。我使用的 laravel 版本是 7.15.0

我希望有一个人可以帮助我。谢谢你。

4

0 回答 0