简体   繁体   English

Mail::queue 关闭序列化错误 Laravel 5.1

[英]Mail::queue Closure serialization error Laravel 5.1

I promise this is not just another Mail::queue newbie question.我保证这不仅仅是另一个 Mail::queue 新手问题。 I had Laravel 4.2 app working with Iron.io Push queues Then, I upgraded to Laravel 5.1 and my Mails just stopped working.我让 Laravel 4.2 应用程序与 Iron.io 推送队列一起工作然后,我升级到 Laravel 5.1 并且我的邮件停止工作。 I have UserController from which I send user account verification email to the registrant.我有 UserController,我从中向注册人发送用户帐户验证电子邮件。

//Used for Mail
$data=['msg'=>$msg];
$details=array(
  'email'=>$email,
  'name'=>$name,
  'subject'=>$subject,
  'msg'=>$msg);
\Mail::queue(['text'=>'emails.contactus'],$data,
  function($message) use ($email,$name,$subject) {
    $message->from($email,$name);
    $message->to(Config::get('app.site_support'))->subject($subject);
});

Iron.io is configured properly with keys and such. Iron.io 已使用密钥等正确配置。 My Mail queuing app and queue processing apps are different.我的邮件排队应用程序和队列处理应用程序是不同的。

Error I get is我得到的错误是

[2015-10-19 18:12:32] production.INFO: Queue POST Item received  
[2015-10-19 18:12:32] production.ERROR: exception 'ErrorException' with message 'Class 'UserController' not found' in /var/www/app/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php:130
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Class 'UserCont...', '/var/www/app...', 130, Array)
#1 /var/www/app/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(130): Closure->bindTo(NULL, 'UserController')
#2 [internal function]: SuperClosure\SerializableClosure->unserialize('a:5:{s:4:"code"...')
#3 /var/www/app/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(300): unserialize('C:32:"SuperClos...')
#4 /var/www/app/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(286): Illuminate\Mail\Mailer->getQueuedCallable(Array)

Looks like Mail::queue is serializing UserControl which is not available in queue/receive processor app.看起来 Mail::queue 正在序列化 UserControl,这在队列/接收处理器应用程序中不可用。 I tried placing UserController in processor app but still get the same error我尝试将 UserController 放在处理器应用程序中,但仍然出现相同的错误

So this is just for another poor soul who's facing the same issue.所以这只是为另一个面临同样问题的可怜人准备的。 After a lot of searching I resorted to a separate Job class that sends email and takes $data (for view template data) and $details (specifying email template, 'to' email address and subject) in its constructor经过大量搜索,我求助于一个单独的 Job 类,该类发送电子邮件并在其构造函数中获取 $data(用于查看模板数据)和 $details(指定电子邮件模板、“收件人”电子邮件地址和主题)

Then I Mail::send in handle method.然后我 Mail::send in handle 方法。

I fire this job using Controllers $this->dispatch method just as they said in Laravel Documentation我使用 Controllers $this->dispatch 方法解雇了这项工作,就像他们在 Laravel 文档中所说的那样

After updating Laravel from 4.2 to 5.1 you need to update the IronMQ version to "4.*" in composer.json.将 Laravel 从 4.2 更新到 5.1 后,您需要在 composer.json 中将 IronMQ 版本更新为“4.*”。 Laravel 5.1 is only compatible with IronMQ v4. Laravel 5.1 仅与 IronMQ v4 兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM