我目前在處理由make:auth in Laravel 5.6
. 我的應用程序託管在 Heroku 上。在我的本地環境中,一切正常。我在 Heroku 的配置變量中設置了正確的值,在我的本地.env
文件中也是如此:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=bla
MAIL_ENCRYPTION=tls
我在這裡讀到我必須對裡面的值進行硬編碼app/mail.php
而不是引用.env
文件,因為 Heroku 不會識別/理解這個引用
'password' => env('MAIL_PASSWORD')
但隨後我的數據將在 GitHub 存儲庫中可見。
問題可能是什麼?
編輯:
接受的答案是正確的答案。應該使用附加組件在 Heroku 中發送郵件。在設置 sendgrid 後,我仍然找到了一種使其與 gmail 一起工作的方法;)
-I had to use `Port 465 with ssl` as encryption.
-Allow `less secure apps` access to my account.
-Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
經過這些步驟,它起作用了。也許這對其他人有幫助。
編輯2:
我將 Laravel 從 5.x 版遷移到 8 版,但再次遇到問題,因此我不得不再次使用 gmail 更改我的方法。
我不得不:
-Allow `less secure apps` access to my account.
-Enable two step verification and create an App Password like in the accepted answer of this question: https://stackoverflow.com/questions/42558903/expected-response-code-250-but-got-code-535-with-message-535-5-7-8-username
-Change Port back to 587 and tls again
-Visit `http://www.google.com/accounts/DisplayUnlockCaptcha` and sign in with your Gmail username and password.
不要在生產環境中使用 Gmail¹。
Gmail 並非旨在充當您的應用程序的 SMTP 網關。相反,使用Heroku 推薦的眾多郵件插件之一。Mailgun 和 SendGrid 都是非常受歡迎的選項,但還有很多其他選項。
這些工具旨在為應用程序發送郵件。他們拒絕您的郵件的可能性會大大降低,並且如果配置正確,您的郵件被垃圾郵件過濾器捕獲的可能性也會大大降低。他們中的大多數都有設置操作的演練,我鼓勵您遵循它們。確保不要跳過SPF和DKIM反垃圾郵件功能。
我在這裡讀到我必須對裡面的值進行硬編碼
app/mail.php
而不是引用.env
文件,因為 Heroku 不會識別/理解這個引用'password' => env('MAIL_PASSWORD')
這是不正確的。
你說你已經在 Heroku 上設置了配置變量,並填充了環境。該.env
文件只是一個方便的本地解決方法,可以做同樣的事情。無論您選擇哪個郵件插件,都會自動為您設置一個或多個環境變量,您應該在代碼中使用這些變量。
¹您可能也不應該在開發中使用它,但這不是問題。我強烈建議您改用 Mailtrap(雲)或 Mailcatcher(本地)之類的東西。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句