laravel项目的Google邮件在cpanel中不起作用

时间:2020-07-15 02:03:23

标签: laravel email gmail cpanel

当我在本地主机上并且一切正常时,我在.env文件中使用以下行:

MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=myaddress@gmail.com
MAIL_PASSWORD=mypwd
MAIL_ENCRYPTION=ssl

但是当我通过cpanel托管laravel项目时,它显示了以下错误:

Connection could not be established with host smtp.googlemail.com :stream_socket_client(): unable to connect to ssl://smtp.googlemail.com:465 (Network is unreachable)

然后我尝试使用以下.env文件,该表单发送了邮件,但实际上却什么也没收到:

MAIL_MAILER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465 //tried amending it to 587
MAIL_USERNAME=myaddress@gmail.com
MAIL_PASSWORD=mypwd
MAIL_ENCRYPTION=ssl //tried amending it to tsl when I changed the port to 587 but still same issue

1 个答案:

答案 0 :(得分:0)

如果不通过第三方应用在Google中启用安全性较低的应用,就无法发送邮件。因此,启用它。

  1. 登录您要用于此的Gmail帐户
  2. 打开URL https://myaccount.google.com/lesssecureapps
  3. 如果关闭,则将其打开。

您的.env文件将如下所示

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_EMAIL_ADDRESS(GMAIL)
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl

在.env文件中进行更改后,请不要忘记运行php artisan config:cache