简体   繁体   中英

Laravel Mail queues with Iron.io

I have been able to get my Iron.io push queue subscription to work great, but not with mail queues for some reason. In the code below I am pushing a job onto the queue with an email address and username in the $data array. For reasons unknown to me, the email address and username are not getting passed to the Mail function. The job just sits there, failing to send.

FooController.php

<?php

$data = array(
    'email_address' => Input::get('email'),
    'username'      => Input::get('username'),
);

Queue::push('SendEmail@reserve', $data);

routes.php

<?php

// iron.io push queue path

Route::post('queue/push', function()
{
    return Queue::marshal();
});


class SendEmail
{
    public function reserve($job, $data)
    {
        Mail::send('emails.reserve', $data, function($message)
        {
            $message->to($data['email_address'], $data['username'])->subject($data['username'] . ', welcome to RockedIn!');
        });
        $job->delete();
    }
}
?>

You need to pass $data to the closure.

public function reserve($job, $data)
{
    Mail::send('emails.reserve', $data, function($message) use ($data)
    {
        $message->to($data['email_address'], $data['username'])->subject($data['username'] . ', welcome to RockedIn!');
    });
    $job->delete();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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