首先需要先安裝套件
composer require guzzlehttp/guzzle
然後配置 config/mail.php (斜體字就填入自己要的名稱)
<?phpreturn ['driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'Your app name'),
'name' => env('MAIL_FROM_NAME', 'Your app name'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'pretend' => true,
];?>
然後上面的設定會去抓 .env 裡面的設定
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME= // 填入 Default SMTP Login 後面的字串
MAIL_PASSWORD= // 填入 Default Password 後面的字串
MAIL_ENCRYPTION=null
MAILGUN_DOMAIN= // 填入 DOMAIN 下面的字串 SandBox...
MAILGUN_SECRET= // 填入 API Key 後面的字串
實際登入Mailgun進入domains會是下面的畫面,就對應上圖填入相對應的值
然後就可以測試寄信功能啦~大概是這樣吧~
祈禱大家照我的方法做都能成功!