【问题标题】:Laravel : how How to send Email using Cron job on Windows?Laravel:如何在 Windows 上使用 Cron 作业发送电子邮件?
【发布时间】:2016-12-16 19:14:17
【问题描述】:

我想在 Windows 上执行 Laravel cron 作业。为此,我从 Tutorial 完成了以下步骤,但 cron 作业在我的应用程序中不起作用。

首先我创建了一个命令:

php artisan make:console SendEmails --command=emails:send

然后我写了代码句柄():

public function handle(Request $request)

    {

        $user=User::all();


            Mail::queue('send', ['user' => $user], function($m) use ($user)

                {

                    foreach ($user as $user) {

                        $m->to($user->email)->subject('Email Confirmation');

                    }                     

                });

    }

然后我在命令数组中添加了以下行:

Commands\SendEmails::class,

并在受保护的计划函数()上添加了以下行:

$schedule->command('SendEmails')

                 ->everyMinute();

所以它应该每分钟发送一次电子邮件。但是没有发送。添加说当我运行命令时,它会立即发送电子邮件,因为发送电子邮件没有问题。

php artisan emails:send

【问题讨论】:

  • cron 不是 Windows 程序。你不能在 Windows 上使用它。您链接的教程面向 *nix 环境。
  • foreach ($user as $user) {?您不能将子变量称为与父变量相同的变量

标签: php laravel laravel-5 cron


【解决方案1】:

您必须在 Windows 中使用该命令schedule a task

【讨论】:

  • 如果你以前做过,请你给个说明好吗..因为我对解决方案不太清楚。
猜你喜欢
  • 2017-05-23
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多