「Php/laravel/laravel5/mail」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==gmailでメールを送る== 事前設定として gmailの設定/imapを無効から有効に ==設定== パスはアプリ認証用に生成(https://security.google...」) |
(→設定) |
||
| 行7: | 行7: | ||
パスはアプリ認証用に生成(https://security.google.com/settings/security/apppasswords) | パスはアプリ認証用に生成(https://security.google.com/settings/security/apppasswords) | ||
| − | vi .env | + | vi .env |
| − | MAIL_DRIVER=smtp | + | MAIL_DRIVER=smtp |
| − | MAIL_HOST=smtp.gmail.com | + | MAIL_HOST=smtp.gmail.com |
| − | MAIL_PORT=587 | + | MAIL_PORT=587 |
| − | MAIL_ENCRYPTION=tls | + | MAIL_ENCRYPTION=tls |
| − | MAIL_FROM_ADDRESS=xxxxxxxx@gmail.com | + | MAIL_FROM_ADDRESS=xxxxxxxx@gmail.com |
| − | MAIL_FROM_NAME=xxxxxxxx | + | MAIL_FROM_NAME=xxxxxxxx |
| − | MAIL_USERNAME=xxxxxxxx@gmail.com | + | MAIL_USERNAME=xxxxxxxx@gmail.com |
| − | MAIL_PASSWORD=xxxxxxxxxxxxxxxx | + | MAIL_PASSWORD=xxxxxxxxxxxxxxxx |
| − | MAIL_PRETEND=false | + | MAIL_PRETEND=false |
| − | vi config/mail.php | + | vi config/mail.php |
| − | 'from' => [ | + | 'from' => [ |
'address' => env('MAIL_FROM_ADDRESS', null), | 'address' => env('MAIL_FROM_ADDRESS', null), | ||
'name' => env('MAIL_FROM_NAME', null) | 'name' => env('MAIL_FROM_NAME', null) | ||
| − | ], | + | ], |
==実行== | ==実行== | ||
2016年8月19日 (金) 10:50時点における版
gmailでメールを送る
事前設定として
gmailの設定/imapを無効から有効に
設定
パスはアプリ認証用に生成(https://security.google.com/settings/security/apppasswords)
vi .env MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=xxxxxxxx@gmail.com MAIL_FROM_NAME=xxxxxxxx MAIL_USERNAME=xxxxxxxx@gmail.com MAIL_PASSWORD=xxxxxxxxxxxxxxxx MAIL_PRETEND=false
vi config/mail.php
'from' => [
'address' => env('MAIL_FROM_ADDRESS', null),
'name' => env('MAIL_FROM_NAME', null)
],
実行
php artisan tinker
Mail::raw('Test Mail', function($message) { $message->to('xxxxxxxxxxxxxxxx@gmail.com')->subject('test'); });
以下エラーが出てしまった。
Swift_TransportException with message 'Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
==envを利用しない場合 configファイルに直書き
vi config/mail.php
return [
'driver' =>'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => [
'address' => 'xxxxxxxx@gmail.com',
'name' => 'xxxxxxxx'
],
'encryption' => 'tls',
'username' => 'xxxxxxxx@gmail.com',
'password' => 'xxxxxxxxxxxxxxxx',
'sendmail' => '/usr/sbin/sendmail -bs',
];
