无法与主机 smtp.gmail.com 建立连接网络无法访问 #101 Laravel 电子邮件中的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45366993/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:23:55  来源:igfitidea点击:

Connection could not be established with host smtp.gmail.com Network is unreachable #101 error in Laravel email

phplaravelemailsmtplaravel-5.1

提问by Vinod VT

I am trying to send email from my laravel 5.1 system. I can send emails from my localhost and unable to send from the server. See my email configuration settings in .env file,

我正在尝试从我的 laravel 5.1 系统发送电子邮件。我可以从我的本地主机发送电子邮件,但无法从服务器发送。在 .env 文件中查看我的电子邮件配置设置,

MAIL_DRIVER=smtp
MAIL_HOST= smtp.gmail.com
MAIL_PORT= 587
MAIL_USERNAME= username***@gmail.com
MAIL_PASSWORD= *********
MAIL_ENCRYPTION=tls

This configuration only work on my localhost. On server I am getting this error,

此配置仅适用于我的本地主机。在服务器上,我收到此错误,

Swift_TransportException in StreamBuffer.php line 268:
Connection could not be established with host smtp.gmail.com [Network is unreachable #101]

I also try with changing MAIL_PORTfrom 587to 465and MAIL_ENCRYPTIONfrom tlsto ssl. But I am geeitng the same error. How can I fix this issue?

我也尝试MAIL_PORT587465MAIL_ENCRYPTIONtlsssl。但我也犯了同样的错误。我该如何解决这个问题?

回答by John

I solved my problem in cpanel using the code:

我使用以下代码在 cpanel 中解决了我的问题:

change MAIL_DRIVER=smtp to MAIL_DRIVER=sendmail in ".env" file

回答by Vishal Varshney

1.) clear the cache on the server after changing the configuration in the .env file.

1.) 更改 .env 文件中的配置后清除服务器上的缓存。

php artisan cache:clear;
php artisan config:cache;

and if the error still comes

如果错误仍然出现

Connection refused is a very explicit and clear error message. It means that the socket connection could not be established because the remote end actively refused to connect.

连接被拒绝是一个非常明确和明确的错误信息。这意味着无法建立套接字连接,因为远程端主动拒绝连接。

It's very unlikely that Google is blocking the connection.

Google 阻止连接的可能性很小。

It's very likely that your web hosting provider has firewall settings that block outgoing connections on port 465, or that they are blocking SMTP to Gmail. 465 is the "wrong" port for secure SMTP, though it is often used, and Gmail does listen there. Try port 587 instead. If the connection is still refused, call your host and ask them what's up.

很可能您的网络托管服务提供商的防火墙设置阻止了端口 465 上的传出连接,或者他们阻止了 SMTP 到 Gmail。465 是安全 SMTP 的“错误”端口,尽管它经常被使用,而且 Gmail 确实在那里侦听。请尝试使用端口 587。如果连接仍然被拒绝,请致电您的主机并询问他们发生了什么事。

回答by Eben Gnanaraj

If your website URL is http://yourdomain.com

如果您的网站 URL 是http://yourdomain.com

you need to use this port 587

你需要使用这个端口 587

or if your website URL is https://yourdomain.com

或者如果您的网站 URL 是https://yourdomain.com

you need to use this port 25

你需要使用这个端口 25

回答by EduardoVida?a

acces to your server and edit nano /etc/csf/csf.conf

访问您的服务器并编辑 nano /etc/csf/csf.conf

SMTP_ALLOWUSER = "cpanel,yourusr"

SMTP_ALLOWUSER = "cpanel,你的用户"

回答by minhhq

Localhost -> worked
Production -> Not Worked
Review your Production Firewall policies or Hosting Provider policies if they blocks email ports (because those ports were heavily spammed)

本地 主机-> 工作
生产 -> 不工作
如果他们阻止电子邮件端口(因为这些端口被大量垃圾邮件发送),请检查您的生产防火墙策略或托管提供商策略