使用gmail发送Laravel 5.5邮件

问题描述 投票:0回答:2

我尝试使用带有gmail的laravel 5.5发送电子邮件时收到错误。

MAIL_DRIVER=smtp
MAIL_HOST=gmail-smtp-msa.l.google.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

我将邮件主机从smtp.google.com更改为了那个,因为我无法访问smtp.google.com

这是我尝试发送邮件时遇到的错误

stream_socket_enable_crypto(): Peer certificate CN=`smtp.gmail.com' did not match expected CN=`gmail-smtp-msa.l.google.com'

这是我在使用mail_host smtp.google.com时使用的错误

Connection could not be established with host smtp.google.com 
[php_network_getaddresses: getaddrinfo failed: Name or service not known #0

请注意,我的测试服务器mailtrap一切正常。那么我怎样才能将这项工作用于生产?

php laravel email
2个回答
5
投票

你在邮件主机MAIL_HOST=smtp.gmail.com有错误

根据你的问题,你使用了MAIL_HOST=gmail-smtp-msa.l.google.comMAIL_HOST=gmail-smtp-msa.l.google.com

但是gmail主机是smtp.gmail.com

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

4
投票

通常设置加密到ssl工作:

'encryption' => 'ssl'

在你的config/mail.php

但你最好试着坚持使用smtp.gmail.com

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
© www.soinside.com 2019 - 2024. All rights reserved.