使用 gmail 发送 Laravel 5.5 邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46282389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send Laravel 5.5 mail using gmail
提问by Willie Mwewa
I have been getting an error while i try to send an email using laravel 5.5 with gmail.
当我尝试使用 laravel 5.5 和 gmail 发送电子邮件时出现错误。
MAIL_DRIVER=smtp
MAIL_HOST=gmail-smtp-msa.l.google.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
I changed the mail host from smtp.google.com to that one becuase i could not reach smtp.google.com
我将邮件主机从 smtp.google.com 更改为那个,因为我无法访问 smtp.google.com
Here is the error i get when i try to send mail
这是我尝试发送邮件时遇到的错误
stream_socket_enable_crypto(): Peer certificate CN=`smtp.gmail.com' did not match expected CN=`gmail-smtp-msa.l.google.com'
And this is the error that i use when i use mail_host smtp.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
Note that everything was working well with my testing server mailtrap. So how can i make this work for production?
请注意,我的测试服务器 mailtrap 一切正常。那么我怎样才能使这项工作适用于生产呢?
回答by iCoders
you have error in mail host MAIL_HOST=smtp.gmail.com
您在邮件主机中出错 MAIL_HOST=smtp.gmail.com
As per your question you have used MAIL_HOST=gmail-smtp-msa.l.google.com
and MAIL_HOST=gmail-smtp-msa.l.google.com
根据您的问题,您使用过MAIL_HOST=gmail-smtp-msa.l.google.com
和MAIL_HOST=gmail-smtp-msa.l.google.com
But gmail host is smtp.gmail.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
回答by Antonio Carlos Ribeiro
Usually setting encryption to ssl works:
通常将加密设置为 ssl 有效:
'encryption' => 'ssl'
On your config/mail.php
:
在您的config/mail.php
:
But you better try to stick with smtp.gmail.com
:
但你最好尝试坚持smtp.gmail.com
:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl