Laravel 5.2:邮件未从 cron-job 发送,从邮件响应中获取错误
Laravel 5.2 : Mail not sending from cron-job, getting error from mail response
正在处理 Laravel 5.2,能够从 API 调用发送邮件,但是从 cron/scheduled 作业发送时出错,
文件权限 :
- app/storage/framework - 777
- vendor/laravel/framework/src - 777
错误信息是:
local.ERROR: exception 'ErrorException' with message 'Undefined variable: errors' in /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php:24
来自日志文件的完整错误消息:
[2018-09-11 10:16:01] local.ERROR: exception 'ErrorException' with message 'Undefined variable: errors' in /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php:24
Stack trace:
#0 /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php(24): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/var/www/html/v...', 24, Array)
#1 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/var/www/html/v...')
#2 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/html/v...', Array)
#3 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get('/var/www/html/v...', Array)
#4 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#5 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#6 /var/www/html/v1/storage/framework/views/80be09fc2f6488124101d105b7ffca95eab87ca3.php(333): Illuminate\View\View->render()
#7 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/var/www/html/v...')
#8 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/html/v...', Array)
#9 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get('/var/www/html/v...', Array)
#10 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#11 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#12 /var/www/html/v1/storage/framework/views/60a5d080fd9cde632d9140e6526f07954901cab0.php(17): Illuminate\View\View->render()
#13 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/var/www/html/v...')
#14 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/html/v...', Array)
#15 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get('/var/www/html/v...', Array)
#16 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#17 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#18 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(441): Illuminate\View\View->render()
#19 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(321): Illuminate\Mail\Mailer->getView('welcome', Array)
#20 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(161): Illuminate\Mail\Mailer->addContent(Object(Illuminate\Mail\Message), 'welcome', NULL, NULL, Array)
#21 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\Mail\Mailer->send('welcome', Array, Object(Closure))
#22 /var/www/html/v1/app/Http/Controllers/ExpenseController.php(1733): Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#23 /var/www/html/v1/app/Http/Controllers/ExpenseController.php(1733): Illuminate\Support\Facades\Mail::send('welcome', Array, Object(Closure))
#24 [internal function]: App\Http\Controllers\ExpenseController->sendMailFromCronTemplate()
#25 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#26 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(602): Illuminate\Container\Container->call(Array, Array)
#27 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): Illuminate\Container\Container->callClass('\App\Http\Contr...', Array, NULL)
#28 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php(61): Illuminate\Container\Container->call('\App\Http\Contr...', Array)
#29 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php(61): Illuminate\Console\Scheduling\CallbackEvent->run(Object(Illuminate\Foundation\Application))
#30 [internal function]: Illuminate\Console\Scheduling\ScheduleRunCommand->fire()
#31 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#32 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#33 /var/www/html/v1/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /var/www/html/v1/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /var/www/html/v1/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Console\Scheduling\ScheduleRunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /var/www/html/v1/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /var/www/html/v1/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 {main}
来自 app/console/kernal.php
的 Cron 函数
protected function schedule(Schedule $schedule)
{
$schedule->call('\App\Http\Controllers\ExController@sendMailFromCron')->cron('* * * * *');
}
邮件功能:
$data = array('name' => "Sample");
$to = 'myname@company.com';
$result = Mail::send('welcome', $data, function($message) use ($to) {
$message->from('myname@company.com', 'Sample');
$message->to($to);
$message->subject('E-Mail Example');
});
查看 Laravel 5.2 doc's,Mail::send()
的第一个参数是模板,您在代码段中指定了 welcome
模板。
welcome
模板通常用作 Web 前端的默认视图,不适用于邮件。我认为根据文档,您想要传递的是 emails.welcome
,但默认情况下不存在。只需在 resources/views/emails
中创建一个电子邮件目录,然后在其中创建一个 welcome.blade.php,其中包含您要通过电子邮件发送的内容。
正在处理 Laravel 5.2,能够从 API 调用发送邮件,但是从 cron/scheduled 作业发送时出错,
文件权限 :
- app/storage/framework - 777
- vendor/laravel/framework/src - 777
错误信息是:
local.ERROR: exception 'ErrorException' with message 'Undefined variable: errors' in /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php:24
来自日志文件的完整错误消息:
[2018-09-11 10:16:01] local.ERROR: exception 'ErrorException' with message 'Undefined variable: errors' in /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php:24
Stack trace:
#0 /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php(24): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined varia...', '/var/www/html/v...', 24, Array)
#1 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/var/www/html/v...')
#2 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/html/v...', Array)
#3 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get('/var/www/html/v...', Array)
#4 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#5 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#6 /var/www/html/v1/storage/framework/views/80be09fc2f6488124101d105b7ffca95eab87ca3.php(333): Illuminate\View\View->render()
#7 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/var/www/html/v...')
#8 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/html/v...', Array)
#9 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get('/var/www/html/v...', Array)
#10 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#11 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#12 /var/www/html/v1/storage/framework/views/60a5d080fd9cde632d9140e6526f07954901cab0.php(17): Illuminate\View\View->render()
#13 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/var/www/html/v...')
#14 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/html/v...', Array)
#15 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): Illuminate\View\Engines\CompilerEngine->get('/var/www/html/v...', Array)
#16 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): Illuminate\View\View->getContents()
#17 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): Illuminate\View\View->renderContents()
#18 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(441): Illuminate\View\View->render()
#19 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(321): Illuminate\Mail\Mailer->getView('welcome', Array)
#20 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(161): Illuminate\Mail\Mailer->addContent(Object(Illuminate\Mail\Message), 'welcome', NULL, NULL, Array)
#21 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\Mail\Mailer->send('welcome', Array, Object(Closure))
#22 /var/www/html/v1/app/Http/Controllers/ExpenseController.php(1733): Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#23 /var/www/html/v1/app/Http/Controllers/ExpenseController.php(1733): Illuminate\Support\Facades\Mail::send('welcome', Array, Object(Closure))
#24 [internal function]: App\Http\Controllers\ExpenseController->sendMailFromCronTemplate()
#25 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#26 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(602): Illuminate\Container\Container->call(Array, Array)
#27 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): Illuminate\Container\Container->callClass('\App\Http\Contr...', Array, NULL)
#28 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php(61): Illuminate\Container\Container->call('\App\Http\Contr...', Array)
#29 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php(61): Illuminate\Console\Scheduling\CallbackEvent->run(Object(Illuminate\Foundation\Application))
#30 [internal function]: Illuminate\Console\Scheduling\ScheduleRunCommand->fire()
#31 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#32 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#33 /var/www/html/v1/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /var/www/html/v1/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /var/www/html/v1/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Console\Scheduling\ScheduleRunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /var/www/html/v1/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#39 /var/www/html/v1/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#40 {main}
来自 app/console/kernal.php
的 Cron 函数protected function schedule(Schedule $schedule)
{
$schedule->call('\App\Http\Controllers\ExController@sendMailFromCron')->cron('* * * * *');
}
邮件功能:
$data = array('name' => "Sample");
$to = 'myname@company.com';
$result = Mail::send('welcome', $data, function($message) use ($to) {
$message->from('myname@company.com', 'Sample');
$message->to($to);
$message->subject('E-Mail Example');
});
查看 Laravel 5.2 doc's,Mail::send()
的第一个参数是模板,您在代码段中指定了 welcome
模板。
welcome
模板通常用作 Web 前端的默认视图,不适用于邮件。我认为根据文档,您想要传递的是 emails.welcome
,但默认情况下不存在。只需在 resources/views/emails
中创建一个电子邮件目录,然后在其中创建一个 welcome.blade.php,其中包含您要通过电子邮件发送的内容。