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
评论列表(0条)