I'm stuck with sending emails with queues in Laravel 4. Let me describe my problem:
This works:
Mail::send('emails.validateEmail', array("username" => Input::get("username"), "code" => $code), function($message){
$message->to(Input::get('email'), Input::get('username'))
->subject('Some subject');
});
However this doesn't work:
Mail::queue('emails.validateEmail', array("username" => Input::get("username"), "code" => $code), function($message){
$message->to(Input::get('email'), Input::get('username'))
->subject('Some subject');
});
I created failed_jobs
table where I keep all failed jobs from worker and in that table I found this error:
{"job":"mailer@handleQueuedMessage","data":{"view":"emails.validateEmail","data":{"username":"some_username","code":"MMgNSoaFcyGoIy10sIKgkwUOdux3tM"},"callback":"C:38:\"Illuminate\\Support\\SerializableClosure\":155:{a:2:{i:0;s:126:\"function ($message) {\n $message->to(\\Input::get('email'), \\Input::get('username'))->subject('Some subject');\n};\";i:1;a:0:{}}}"}}
Also I found this: http://forumsarchive.laravel.io/viewtopic.php?id=12672
.. I followed all instructions from previous link but I'm keep getting this error message.
Does anyone knows how to solve this?
EDIT: emails.validateEmail file
Hello {{ $username }}!<br>
<p>some text</p><br>
<a href="{{ URL::route('validate') }}?code={{ $code }}&username={{ $username }}">{{ URL::route("validate") }}?code={{ $code }}&username={{ $username }}</a><br><br>
some more text
Looking at your error job - it seems like it is passing in the Input::get()
commands into the serialization, rather than the data from those commands.
So I think you need to do something like this to make it work:
$data['email'] = Input::get('email');
$data['username'] = Input::get('username');
Mail::queue('emails.validateEmail', array("username" => Input::get("username"), "code" => $code), function($message) use ($data){
$message->to($data['email'], $data['username'])->subject('Some subject');
});