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
mailer_JsonException

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (15 by maintainers)

Commits related to this issue

Most upvoted comments

This takes to install the fixed version:

composer.json

"require": {
    "symfony/mailgun-mailer": "4.4.x-dev as 4.3",
    "symfony/mailer": "4.4.x-dev as 4.3",
    "symfony/mime": "4.4.x-dev as 4.3"
}

Then update those:

composer update symfony/mailgun-mailer symfony/mailer symfony/mime --with-dependencies

Problem

So I could got the error message:

The “http” scheme is not supported.

Solution

-MAILER_DSN="http://$MAILGUN_KEY:$MAILGUN_DOMAIN@mailgun"
+MAILER_DSN="mailgun://$MAILGUN_KEY:$MAILGUN_DOMAIN@mailgun"

This seems fixed in recipe for symfony/mailgun-mailer 4.4 in flex: https://github.com/symfony/recipes/blob/master/symfony/mailgun-mailer/4.4/manifest.json

But 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

MAILER_DSN=http://$MAILGUN_API_KEY:$MAILGUN_DOMAIN@mailgun

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?