最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论