symfony: [Mailer] JsonException is thrown when calling `send()` method
Symfony version(s) affected: 4.3.1
Description
I’m using the new Symfony Mailer, on a real app production environment some of this issue has happened:
Symfony\Component\HttpClient\Exception\JsonException
Response content-type is "text/html; charset=utf-8" while a JSON-compatible one was expected.
This error has been thrown by $this->mailer->send($email)
I’m also using symfony/mailgun-mailer
How to reproduce
I don’t know, sorry 😦
Possible Solution
Wrap the $this->mailer->send($email); in a try/catch block, but not sure how this error happens, and how to prevent it, or deal with it.
Additional context

About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (15 by maintainers)
This takes to install the fixed version:
composer.jsonThen update those:
Problem
So I could got the error message:
Solution
This seems fixed in recipe for
symfony/mailgun-mailer4.4 in flex: https://github.com/symfony/recipes/blob/master/symfony/mailgun-mailer/4.4/manifest.jsonBut will not override anything installed in 4.3
Just had the issue, here is the fix: #33432
I have same problem with 4.3.3. Using also mailgun. I just migrate my code to “symfony/mailer” and “symfony/mailgun-mailer”. Using api
Response content-type is “text/html; charset=utf-8” while a JSON-compatible one was expected.
I’m using the API.
I think it’s important to understand what this HTML is about before improving the exception type. Could you please try to understand this better?