Laravel 5.2:邮件未从cron-job发送,从邮件响应中获取错误

时间:2018-09-11 10:51:59

标签: php laravel laravel-5.2 laravel-mail

使用Laravel 5.2进行工作,能够通过API调用发送邮件,但是在通过cron /预定作业发送邮件时出现错误

文件权限

  • 应用程序/存储/框架-777
  • 供应商/ laravel / framework / src-777

错误消息是

<div class="wrapper">
  <!-- section 1 -->
  <section id="section-1" class="sec_wrapper parallax">
    <div class="top-content parallax">
      <div class="welcome-txt">
        <p style="text-align: center;">hello! how are you?<br>we are</p>
      </div>
    </div>
  </section>

  <section id="section-2" class="sec_wrapper ">

  </section>
</div>

日志文件中的完整错误消息:

local.ERROR: exception 'ErrorException' with message 'Undefined variable: errors' in /var/www/html/v1/storage/framework/views/258d88011f525ffcc409e29eafacedd9b8048ff6.php:24

app / console / kernal.php中的Cron函数

[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}

邮件功能:

protected function schedule(Schedule $schedule)
    {
        $schedule->call('\App\Http\Controllers\ExController@sendMailFromCron')->cron('* * * * *');
    }

1 个答案:

答案 0 :(得分:0)

Laravel 5.2 doc's为例,Mail::send()的第一个参数是模板,在代码段中,您指定了welcome模板。

welcome模板通常用作Web前端(而不是邮件)的默认视图。我认为您要传递的是根据文档的emails.welcome,但默认情况下不会存在。只需在resources/views/emails中创建一个电子邮件目录,并在其中创建包含您想通过电子邮件发送的内容的welcome.blade.php。