October: Mail queue with closure Exception

Created on 27 Apr 2017  路  5Comments  路  Source: octobercms/october

Expected behavior

email sent by queuing

Actual behavior

Mail::queue($mailTemplate, $model->getNotificationVars(), function($message) use ($user) {
$message->to($user->email, $user->name);
});

give the exception

````cmd
[2017-04-27 22:07:27] dev.ERROR: exception 'ErrorException' with message 'Serialization of closure failed: Serialization of 'Closure' is not allowed' in /Users/chris/Sites/asia/site/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php:117
Stack trace:

0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(1024, 'Serialization o...', '/Users/chrisvid...', 117, Array)

1 /Users/chris/Sites/asia/site/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(117): trigger_error('Serialization o...', 1024)

2 [internal function]: SuperClosure\SerializableClosure->serialize()

3 /Users/chris/Sites/asia/site/vendor/jeremeamia/SuperClosure/src/Serializer.php(69): serialize(Object(SuperClosure\SerializableClosure))

4 /Users/chris/Sites/asia/site/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(272): SuperClosure\Serializer->serialize(Object(Closure))

5 /Users/chris/Sites/asia/site/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(193): Illuminate\Mail\Mailer->buildQueueCallable(Object(Closure))

````

October build

415

Completed Bug

Most helpful comment

Fixed in Build 430+

All 5 comments

What queue driver are you utilizing?

the default one, the 'sync'

Try passing something other than object to the closure

$email = $user->email;
$name = $user->name;

Mail::queue($mailTemplate, $model->getNotificationVars(), function($message) use ($email, $name) {
    $message->to($email, $name);
});

I am getting a similar error after L5.5 upgrade. I have a plugin with this code:

// add the recipient data
$data['recipient'] = ['email' => $email, 'name' => $name];

/**
 * email configuaration array
 * @var array
 */
$email = [
    'from_email' => Settings::get('from_email'),
    'from_name' => Settings::get('from_name'),
    'sender_email' => Settings::get('from_email'),
    'sender_name' => Settings::get('from_name'),
    'reply_to_email' => Settings::get('from_email'),
    'reply_to_name' => Settings::get('from_name'),
    'subject' => $mail->subject,
    'to_email' => $email,
    'to_name' => $name,
];

// send the email
if ($mail->delay) {

    Mail::later($mail->delay, $mail->template, ['data' => $data], function($message) use ($email) {
        $message->from($email['from_email'], $email['from_name']);
        $message->replyTo($email['reply_to_email'], $email['reply_to_name']);
        $message->subject($email['subject']);

        $message->to($email['to_email'], $email['to_name']);
    });
}
else {
    Mail::send($mail->template, ['data' => $data], function($message) use ($email) {
        $message->from($email['from_email'], $email['from_name']);
        $message->replyTo($email['reply_to_email'], $email['reply_to_name']);
        $message->subject($email['subject']);

        $message->to($email['to_email'], $email['to_name']);
    });
}

The contents of $email are all strings, so no objects. Any ideas? For the time being, I have changed Mail::queue to Mail::send, which works fine.

I am using the database queue connection at the moment but tried sync too with the same result. On Homestead dev environment and Mailgun sandbox setup.

Regards,
Mat

Fixed in Build 430+

Was this page helpful?
0 / 5 - 0 ratings