php - Laravel 11 how to configure email encoding? - Stack Overflow

I'm sending emails from Laravel 11 app via SMTP (SendGrid) and viewing them in Gmail.My HTML emai

I'm sending emails from Laravel 11 app via SMTP (SendGrid) and viewing them in Gmail.

My HTML email has correct encoding configured:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

However, when I click "Show original" in Gmail and check both text and HTML versions of the email, I see other encodings:

Either "iso-8859-1"

Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
...plain text email...
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
...html email...

Or "us-ascii":

Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
...plain text email...
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
...html email...

I want everything to be UTF-8 of course.

For the life of me can't find in laravel or sendgrid docs how I can configure the correct encoding. All advice given by LLMs are hallucinations or code from previous laravel versions.

Incorrect encoding creates issues when I use special characters from other languages, like german umlauts.

My email is fairly simple:

$payload = [
    'url' => route('login.verify', ['token' => $token]),
];
Mail::to($user->email)->send(new EmailOTP($payload));
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class EmailOTP extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public array $data)
    {
    }

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Your login link',
        );
    }

    public function content(): Content
    {
        return new Content(
            markdown: 'emails.login-link',
            with: [
                'url' => $this->data['url'],
            ],
        );
    }
}

How can I configure emails beint sent to be UTF-8?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744762491a4592254.html

相关推荐

  • php - Laravel 11 how to configure email encoding? - Stack Overflow

    I'm sending emails from Laravel 11 app via SMTP (SendGrid) and viewing them in Gmail.My HTML emai

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信