Laravel 9: Malformed characters for emails in laravel.log

Viewed 25

If I adjust in my Laravel 9 project (PHP 8), the .env - file to MAIL_MAILER=log. The mail is saved in the laravel.log file, but the problem is, that some characters are malformed. For example the mail-<head> looks like this:

<head>
    <meta charset=3D"utf-8">
    <meta name=3D="viewport" content=3D"width=3Ddevice-width, initial-scale=3D1.0">
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8">
    <meta name=3D"color-scheme" content=3D"light">
    <meta name=3D"supported-color-schemes" content=3D"light">
</head>

The malformed characters also occur for äöü and other UTF-8 characters (e.g. ä resolves to =C3=A4). If I'm using MAIL_MAILER=smtp the mail isn't malformed at all. This makes local email debugging hard.

Anyway, this probably causes another problem on production. I'm using the package (https://github.com/shvetsgroup/laravel-email-database-log) to save all sent mails of Laravel in the database. Here the malformed characters are also saved in the database.

I'm sending mails like this:

\Illuminate\Support\Facades\Mail::to('mail@mail.de')->queue(new \App\Mail\ContactConfirmation(
    $name,
    $message
));

class ContactConfirmation extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public string $name,
        public string $text
    )
    {
        //
    }

    public function build()
    {
        return $this->markdown('mails.contact_confirmation')
            ->subject('Your message')
            ->with([
                'name' => $this->name,
                'text' => $this->text
            ]);
    }
}

This problem looks similar to https://github.com/laravel/framework/issues/32954, but the mails sent by SMTP have no problem and Laravel 9 uses the Symfony Mailer. There is also a similar question (Why does Laravel replace a tab by a "=09" string when sending mails?) from 2014, but here is SwiftMailer used.

Is there some way to fix the malformed characters on production and local? And if not, are there alternatives to save the mail without the package and malformed characters into the database?

0 Answers
Related