作爲測試,當我訪問我的'/'路由時,我有相關的控制器發送測試郵件。不過,我收到此錯誤:使用Laravel 5.2連接Maligun API時發送郵件
客戶端錯誤:POST https://api.mailgun.net/v3/My domain name/messages.mime
導致了401 UNAUTHORIZED
響應: 故宮
這裏是我的控制器。
public function index()
{
$data = [];
\Mail::send('emails.test', $data, function($message)
{
$message->to('[email protected]')->subject('test email');
});
}
我認爲問題在於我設置的mailgun API。這裏是我的.env文件,我設置了我的郵件。我不確定我是否正確使用我的API密鑰和域名。
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=port number (which is different to that in the mail.php file)
MAIL_USERNAME=My domain name
MAIL_PASSWORD=My API Key
MAIL_ENCRYPTION=tls
這裏是我的mail.php文件
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '[email protected]', 'name' => 'Test'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('My domain name'),
'password' => env('My API Key'),
'sendmail' => '/usr/sbin/sendmail -bs',
我也有這個在我的services.php文件
'mailgun' => [
'domain' => 'My domain name',
'secret' => 'My API key',
],
我composer.json文件
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*",
"guzzlehttp/guzzle": "~5.3|~6.0"
},
感謝您的建議。但是,我仍然遇到同樣的錯誤。 – DanielPahor
MAILGUN_SECRET和MAIL_PASSWORD不一樣。請檢查更新! –