dcblogdev / laravel-sent-emails

Store outgoing emails in Laravel
MIT License
249 stars 24 forks source link

Unable to JSON encode payload. Error code: 5 #1

Closed Bouhnosaure closed 4 years ago

Bouhnosaure commented 4 years ago

Hi,

I've spent 4 hours debugging because, i had an issue with a behavior of this library !

Long story short, i you use a queue system to send notifications, you might want to consider encoding your email to utf8 or try to remove as much as possible characters that can cause a json_encode to crash.

On my side, i was sending a job in order to send a notification with a model in payload ( my jobs a chained, that's why i don't use directly the notification system, it has worked for 6 months without issue ).

But the issue is that when my job was fired, it will enqueue the notification and because the listener ( to catch mail ) has to lisent to the MessageSending event, it will be enqueued as well, so a the moment when all the queue is processed, i had this weird error telling me that the payload cannot be encoded so i've struggled a long moment before giving up and at this precise moment i've tried to dump and dd everywhere in the vendor/laravel/framework/src/Illuminate/Queue/Queue.php file and by chance the dump had print before the error was throw and i got this :

image

But those characters weren't the problem, it's the ones in the bottom :

image

So for me i'll roll my own mailcatcher i think but i hope my issue can help someone later :)

Thanks !

dcblogdev commented 4 years ago

Thanks for raising the issue, I've never used queue's. I'd be happy to accept a PR if you managed to find a workaround.

Bouhnosaure commented 4 years ago

Hi !

For the moment I've not found yet a solution, i'll take a look later as this is a needed feature in my system.

I'll try to either get the content of the mail as text only or maybe parse the html produced by the email and convert it to markdown because saving the entire content of the mail will increase the size of the database quickly

You can close the issue for now if you want i just wanted to share my experience,

I'll reopen it when i'll have to work on it and get a solution !

dcblogdev commented 4 years ago

thanks, I appreciate that.