2015年5月6日 星期三

在 Laravel 5 使用 Gmail 寄送郵件

Gmail 的外寄郵件伺服器設定:

server: smtp.gmail.com
TLS port: 587
SSL port: 465

修改專案目錄下的 config/mail.php
 env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'xxxxxx@gmail.com', 'name' => 'xxxxxx'],
    'encryption' => 'tls',
    'username' => env('xxxxxx@gmail.com'),
    'password' => env('******'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
];

使用環境變數的話,修改專案目錄下的 .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx@gmail.com
MAIL_PASSWORD=******
沒有 .env 可以複製預設的環境變數設定
$ cp .env.example .env
使用預設的環境變數設定,寄送郵件會因為沒有設定 from 而發生錯誤,可以修改 config/mail.php
     'from' => ['address' => env('MAIL_FROM'), 'name' => env('MAIL_SENDER_NAME')],
在 .env 再加入 MAIL_FROM 和 MAIL_DISPLAY_NAME 解決問題
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx@gmail.com
MAIL_PASSWORD=******
MAIL_FROM=xxxxxx@gmail.com
MAIL_SENDER_NAME=xxxxxx
有使用兩步驟驗證的話,要到Google 帳戶的應用程式密碼產生專用的密碼

參考

1 則留言:

  1. We are going to discuss a number of} of probably the most thrilling on line casino games you could play on Xbox and really feel the thriller you had whereas competing in a on line casino. This strategy is taken into account the best way|one of the only ways|the easiest way} to kill your time and make it enjoyable. So, with none further explanation, let’s https://zkwlsh.com/ begin with the on line casino games on our listing. There are in depth and important variations between paying/funded players in the social gaming and on-line playing domains. We hope that the info presented in this article can present deeper perception into the variations between social gamers and on-line gamblers.

    回覆刪除