The main difference between the synchronous send()
and the asynchronous queue()
, as far as your ForgotPassword
object is concerned, is that when you queue the object for sending, it must be serialized to be sent to the queue, and unserialized when the queue worker processes it.
Since send()
works fine, but an error is occurring with queue()
, and we can see that the queued job is fired and being attempted to be processed, there is most likely an error in the serialization/unserialization.
Your ForgotPassword
class is probably using the SerializesModels
trait, since that is how the artisan command generates a new mailable object. This trait defines __sleep()
and __wakeup()
methods, which modify how serialization and unserialization work.
When the __sleep
method is implemented, PHP will only serialize the variables that are returned by the __sleep
method. In this case, the implementation provided by the SerializesModels
trait uses Reflection to go through the properties defined on the class to provide a special way to serialize Eloquent models and collections.
Because of this, this means that any variables on your ForgotPassword
class that are not specifically defined as a property on the class will not get serialized, and it will not be available when the queued job is processed and the class is unserialized. This is the most likely reason for your issue. When your job is being attempted, your unserialized mailable instance doesn't have the data it needs, and is failing.
There are two ways to resolve this. First, if your ForgotPassword
does not actually need to serialize any models, you can remove the SerializedModels
trait. This will remove the __sleep()
definition from the class, and then all variables assigned on the class, not just those actually defined, will be serialized, and will also be available when the class is unserialized.
The second option, which is more appropriate and more explicit, is to actually define the properties you need on your ForgotPassword
class.
If you define the properties on your class, you could leave the SerializesModels
trait on your class. However, if you aren't actually serializing models, I'd go ahead and remove it. No need for the extra serialization overhead if you don't need it.
tail -f storage/logs/laravel.log
, do you see any errors logged? – HodmanMail::to
line doesn't give error. Butphp artisan queue:listen
command results inSQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'attempts'
. – Goegerattempts
? You may want to change to something bigger, likeBIGINT
– HodmanJobs
table. – Goegerattempts
column, which istinyInteger
, can carry. One way to solve that would be to add apublic $tries = 5;
or some other number to your job class. @Goeger – HodmanForgotPassword
should be aMailable
. Your queue is attempting to send the mail, but it is failing for some reason. Can you post yourForgotPassword
class? Also, are there no other log entries that might explain why the job is failing? – Drillstock