我正在使用Laravel队列来让我的邮件正常运行。我的SendMail
课程是这样的
class SendMail {
public static function sendAbuseEmail($job,$data, $toEmail,
$subject, $fromEmail, $fromName) {
Mail::send(array('html' => 'emails.abuseUrl.abuse'),
$data, function ($m) use ($toEmail, $subject,
$fromEmail, $fromName) {
$m->from($fromEmail, $fromName);
$m->to($toEmail)->subject($subject);
});
$job->delete();
}
}
我正在使用它
$data = array('name' => Input::get('name'),
'quote' => Input::get('quote'),
'from' => Input::get('email'),
'abuseUrl'=> Input::get('abuseUrl'));
$subject = Input::get('subject');
$toEmail = Config::get('settings.adminEmail');
$fromEmail = Input::get('email');
$fromName = Input::get('name');
Queue::push('SendMail@sendAbuseEmail', $data,$toEmail,
$subject, $fromEmail, $fromName);
但是我收到了错误
[2014-08-20 17:25:41] production.ERROR:异常'ErrorException',消息'Codeforge \ Mailers \ SendMail :: sendAbuseEmail()缺少参数3,在/ var / www / laravel /中调用第96行上的vendor / laravel / framework / src / Illuminate / Queue / Jobs / Job.php并在/var/www/laravel/app/Codeforge/Mailers/SendMail.php:1
中定义
我在这里做错了什么?
答案 0 :(得分:1)
查看QueueInterface#push()的方法签名:
public function push($job, $data = '', $queue = null);
$data
can be anything that's json_encode
able。而不是传递有序参数,约定是传递一个关联数组:
Queue::push('SendMail@sendAbuseEmail', array(
'data' => $data,
'toEmail' => $toEmail,
'subject' => $subject,
'fromEmail' => $fromEmail,
'fromName' => $fromName
));
在您的工作人员中,您可以访问以下值:
public static function sendAbuseEmail($job, array $data)
{
$toEmail = $data['toEmail'];
// etc...
}
这是因为所有驱动程序(Sync
驱动程序除外)都需要序列化这些数据并将其写入某种数据存储区以供以后参考。我相信它是以这种方式设计的,因为它更容易跟踪它是否是单个对象。