Laravel 5.2:邮件没有从cron-job发送,从邮件响应中收到错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Laravel 5.2:邮件没有从cron-job发送,从邮件响应中收到错误相关的知识,希望对你有一定的参考价值。
在Laravel 5.2上工作,能够从API调用发送邮件,但在从cron /预定作业发送时收到错误,
文件权限:
- 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): IlluminateFoundationBootstrapHandleExceptions->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): IlluminateViewEnginesPhpEngine->evaluatePath('/var/www/html/v...', Array)
#3 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): IlluminateViewEnginesCompilerEngine->get('/var/www/html/v...', Array)
#4 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): IlluminateViewView->getContents()
#5 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): IlluminateViewView->renderContents()
#6 /var/www/html/v1/storage/framework/views/80be09fc2f6488124101d105b7ffca95eab87ca3.php(333): IlluminateViewView->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): IlluminateViewEnginesPhpEngine->evaluatePath('/var/www/html/v...', Array)
#9 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): IlluminateViewEnginesCompilerEngine->get('/var/www/html/v...', Array)
#10 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): IlluminateViewView->getContents()
#11 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): IlluminateViewView->renderContents()
#12 /var/www/html/v1/storage/framework/views/60a5d080fd9cde632d9140e6526f07954901cab0.php(17): IlluminateViewView->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): IlluminateViewEnginesPhpEngine->evaluatePath('/var/www/html/v...', Array)
#15 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(149): IlluminateViewEnginesCompilerEngine->get('/var/www/html/v...', Array)
#16 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(120): IlluminateViewView->getContents()
#17 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/View/View.php(85): IlluminateViewView->renderContents()
#18 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(441): IlluminateViewView->render()
#19 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(321): IlluminateMailMailer->getView('welcome', Array)
#20 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(161): IlluminateMailMailer->addContent(Object(IlluminateMailMessage), 'welcome', NULL, NULL, Array)
#21 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): IlluminateMailMailer->send('welcome', Array, Object(Closure))
#22 /var/www/html/v1/app/Http/Controllers/ExpenseController.php(1733): IlluminateSupportFacadesFacade::__callStatic('send', Array)
#23 /var/www/html/v1/app/Http/Controllers/ExpenseController.php(1733): IlluminateSupportFacadesMail::send('welcome', Array, Object(Closure))
#24 [internal function]: AppHttpControllersExpenseController->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): IlluminateContainerContainer->call(Array, Array)
#27 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Container/Container.php(502): IlluminateContainerContainer->callClass('\App\Http\Contr...', Array, NULL)
#28 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php(61): IlluminateContainerContainer->call('\App\Http\Contr...', Array)
#29 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php(61): IlluminateConsoleSchedulingCallbackEvent->run(Object(IlluminateFoundationApplication))
#30 [internal function]: IlluminateConsoleSchedulingScheduleRunCommand->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): IlluminateContainerContainer->call(Array)
#33 /var/www/html/v1/vendor/symfony/console/Command/Command.php(256): IlluminateConsoleCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#34 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#35 /var/www/html/v1/vendor/symfony/console/Application.php(794): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#36 /var/www/html/v1/vendor/symfony/console/Application.php(186): SymfonyComponentConsoleApplication->doRunCommand(Object(IlluminateConsoleSchedulingScheduleRunCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#37 /var/www/html/v1/vendor/symfony/console/Application.php(117): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#38 /var/www/html/v1/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#39 /var/www/html/v1/artisan(36): IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#40 {main}
来自app / console / kernal.php的Cron功能
protected function schedule(Schedule $schedule)
{
$schedule->call('AppHttpControllersExController@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:邮件没有从cron-job发送,从邮件响应中收到错误的主要内容,如果未能解决你的问题,请参考以下文章
Laravel 5.2 邮件发送中的 Swift_TransportException