php SMTP Connect() 失败。邮件未发送。邮件程序错误:SMTP Connect() 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18496650/
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
SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed
提问by Sayari
Am trying to send mail to a gmail address but it keeps on getting this error "SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed." What could be the problem?
我正在尝试将邮件发送到 gmail 地址,但它不断收到此错误“SMTP -> 错误:无法连接到服务器:连接超时(110)SMTP 连接()失败。消息未发送。邮件程序错误:SMTP 连接() 失败的。” 可能是什么问题呢?
require 'class.phpmailer.php'; // path to the PHPMailer class
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "mypasswword"; // SMTP password
$Mail->Priority = 1;
$mail->AddAddress("[email protected]","Name");
$mail->SetFrom($visitor_email, $name);
$mail->AddReplyTo($visitor_email,$name);
$mail->Subject = "Message from Contact form";
$mail->Body = $user_message;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
回答by Snehasis
Remove or comment out the line-
删除或注释掉该行-
$mail->IsSMTP();
And it will work for you.
它会为你工作。
I have checked and experimented many answers from different sites but haven't got any solution except the above solution.
我已经检查并试验了来自不同站点的许多答案,但除了上述解决方案之外没有任何解决方案。
回答by El David
You must to have installed php_openssl.dll, if you use wampserver it's pretty easy, search and apply the extension for PHP.
您必须已经安装了 php_openssl.dll,如果您使用 wampserver,这很容易,搜索并应用 PHP 扩展。
In the example change this:
在示例中更改此:
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 465 ssl
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
and then you recived an email from gmail talking about to enable the option to Less Safe Access Applications here https://www.google.com/settings/security/lesssecureapps
然后你收到了一封来自 gmail 的电子邮件,谈论在此处启用“不太安全的访问应用程序”的选项https://www.google.com/settings/security/lesssecureapps
I recommend you change the password and encrypt it constantly
我建议您更改密码并不断加密
回答by Dmitri DB
You've got no SMTPSecure setting to define the type of authentication being used, and you're running the Host setting with the unnecessary 'ssl://' (PS -- ssl is over port 465, if you need to run it over ssl instead, see the accepted answer here. Here's the lines to add/change:
您没有 SMTPSecure 设置来定义正在使用的身份验证类型,并且您正在运行带有不必要的“ssl://”的主机设置(PS - ssl 通过端口 465,如果您需要运行它ssl,请参阅此处接受的答案。这是要添加/更改的行:
+ $mail->SMTPSecure = 'tls';
- $mail->Host = "ssl://smtp.gmail.com";
+ $mail->Host = "smtp.gmail.com";
回答by Sendoh Akira
Are you running on Localhost? and have you edit the php.ini
?
你在本地主机上运行吗?你编辑了php.ini
吗?
If not yet, try this:
1. Open xampp->php->php.ini
2. Search for extension=php_openssl.dll
3. The initial will look like this ;extension=php_openssl.dll
4. Remove the ';' and it will look like this extension=php_openssl.dll
5. If you can't find the extension=php_openssl.dll
, add this line extension=php_openssl.dll
.
6. Then restart your Xampp.
如果还没有,试试这个:
1. 打开 xampp->php->php.ini
2. 搜索extension=php_openssl.dll
3. 初始看起来像这样;extension=php_openssl.dll
4. 删除 ';' 它看起来像这样extension=php_openssl.dll
5. 如果找不到extension=php_openssl.dll
,请添加这一行extension=php_openssl.dll
。
6. 然后重启你的 Xampp。
Goodluck ;)
祝你好运 ;)
回答by Goldbug
I know its been a while since this question but I had the exact problem and solved it by disabling SMTP_BLOCK on csf.conf (we use CSF for a firewall).
我知道这个问题已经有一段时间了,但我遇到了确切的问题,并通过在 csf.conf 上禁用 SMTP_BLOCK 来解决它(我们使用 CSF 作为防火墙)。
To disable just edit csf.conf and disable SMTP_BLOCK like so:
要禁用只需编辑 csf.conf 并禁用 SMTP_BLOCK,如下所示:
###############################################################################
# SECTION:SMTP Settings
###############################################################################
# Block outgoing SMTP except for root, exim and mailman (forces scripts/users
# to use the exim/sendmail binary instead of sockets access). This replaces the
# protection as WHM > Tweak Settings > SMTP Tweaks
#
# This option uses the iptables ipt_owner/xt_owner module and must be loaded
# for it to work. It may not be available on some VPS platforms
#
# Note: Run /etc/csf/csftest.pl to check whether this option will function on
# this server
# SMTP_BLOCK = "1" --> this will cause phpmailer Connection timed out (110)
SMTP_BLOCK = "0"
回答by user5778000
i've had this problem in tell i recive an email from google telling me that someone try to login to your account is it you and i answer yes then it start workin so if this is the case for you look in your email and allow the server
我遇到了这个问题,告诉我收到了一封来自谷歌的电子邮件,告诉我有人试图登录你的帐户是你吗,我回答是,然后它开始工作,所以如果是这种情况,请查看您的电子邮件并允许服务器
回答by user7347514
Login your Google account at myaccount.google.com/securitygo to "Login" and then "Security", scroll to bottom then enable the "Allow less secure apps" option.
在myaccount.google.com/security 上登录您的 Google 帐户,转到“登录”,然后转到“安全性”,滚动到底部,然后启用“允许安全性较低的应用程序”选项。
回答by ????? ?????
Here is a list of this you should look into when dealing with PHPMailer:
这是您在处理 PHPMailer 时应该查看的列表:
- Enable openSSL by un-commenting
extension=php_openssl.dll
in your PHP.ini - Use
$mail->SMTPSecure = 'tls';
and$mail->Port = 587;
- Enable debugging for if you are going wrong somewhere else like incorrect username and password etc.
- 通过
extension=php_openssl.dll
在 PHP.ini 中取消注释来启用openSSL - 使用
$mail->SMTPSecure = 'tls';
和$mail->Port = 587;
- 如果您在其他地方出错,例如不正确的用户名和密码等,请启用调试。
回答by deepak kumar
You are doing all well. Just you have to check different SMTP ports like 465 and others that works on your system.
Another thing to keep in mind to allow access to the less secure appsby google account otherwise it throws the same error.
I have gone through it for a whole day and the only thing I am doing wrong is the port no., I just changed the port no. and it works.
你一切都很好。只是您必须检查不同的 SMTP 端口,例如 465 和其他适用于您系统的端口。要记住的另一件事是允许通过谷歌帐户访问 安全性较低的应用程序,否则会引发相同的错误。
我已经经历了一整天,唯一做错的是端口号,我只是更改了端口号。它有效。
回答by Stephanie
If it works on your localhost but not on your web host:
如果它适用于您的本地主机但不适用于您的网络主机:
Some hosting sites block certain outbound SMTP ports. Commenting out the line $mail->IsSMTP();
as noted in the accepted answer may make it work, but it is simply disabling your SMTP configuration, and using the hosting site's email config.
某些托管站点会阻止某些出站 SMTP 端口。注释掉已$mail->IsSMTP();
接受答案中所述的行可能会使其工作,但它只是禁用您的 SMTP 配置,并使用托管站点的电子邮件配置。
If you are using GoDaddy, there is no way to send mail using a different SMTP. I was using SiteGround, and found that they were allowing SMTP access from ports 25 and 465 only, with an SSL encryption type, so I would look up documentation for your host and go from there.
如果您使用的是 GoDaddy,则无法使用不同的 SMTP 发送邮件。我正在使用 SiteGround,发现他们只允许从端口 25 和 465 进行 SMTP 访问,使用 SSL 加密类型,因此我会查找您的主机的文档并从那里开始。