LoginSignup
5
3

More than 3 years have passed since last update.

Laravel5.8 メールの件名(From)が文字化けしてしまう時の対処法

Posted at

ユーザ向けの自動返信メールのFrom(送信者情報)を変えたところ文字化けしてしまったので自分用メモ

app/Mail/Mail.php
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class Contact extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($mail)
    {
        // Fromメールアドレス
        $this->mail = $mail;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        // mb_encode_mimeheader()でFromをエンコードする
        return $this->from($this->mail, mb_encode_mimeheader('〇〇運営事務局'))
        ->subject('HPからのお問い合わせありがとうございます。')
        ->text('mails/contact');
    }
}

ぶっちゃけLaravelはそんなに関係ないメールあるあるだけど、迷える子羊のために(自分)残しておく

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3