LoginSignup
5
2

More than 1 year has passed since last update.

GmailでLaravelから爆速メール送信

Last updated at Posted at 2023-04-25

2段階認証を有効

アプリ パスワードは 2 段階認証プロセスを有効にしているアカウントでのみ使用できます。
https://support.google.com/accounts/answer/185833?hl=ja
image.png

2段階認証を有効にしてください
https://myaccount.google.com/security

image.png

アプリパスワードを作成

アプリパスワードを作りましょう
https://myaccount.google.com/apppasswords

Screenshot from 2023-04-25 20-27-18.png
Screenshot from 2023-04-25 20-27-31.png
Screenshot from 2023-04-25 20-27-42.png
image.png

Screenshot from 2023-04-25 20-28-22.png

.envを修正

MAIL_USERNAMEMAIL_PASSWORDは書き換えてや

.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=hoge@gmail.com
MAIL_PASSWORD=16文字のパスワード
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="${MAIL_USERNAME}"

メール送信 動作確認

php artisan tinker

Mail::send([], [], function ($message) {
    $message->to('fuga@gmail.com');
    $message->subject('Sample test');
    $message->setBody('<h1>It works!</h1>', 'text/html');
});

2段階認証をオフにするとメール送信できなくなりますのでご注意願う

5
2
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
2