Php SMTP连接()失败。邮件未发送。邮件程序错误:SMTP Connect()失败
我试图将邮件发送到gmail地址,但它不断收到以下错误“SMTP->错误:无法连接到服务器:连接超时(110)SMTP connect()失败。邮件未发送。邮件程序错误:SMTP connect()失败。”可能是什么问题Php SMTP连接()失败。邮件未发送。邮件程序错误:SMTP Connect()失败,php,email,smtp,Php,Email,Smtp,我试图将邮件发送到gmail地址,但它不断收到以下错误“SMTP->错误:无法连接到服务器:连接超时(110)SMTP connect()失败。邮件未发送。邮件程序错误:SMTP connect()失败。”可能是什么问题 require 'class.phpmailer.php'; // path to the PHPMailer class require 'class.smtp.php'; $mail = new PHPMailer(
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 = "myemail@gmail.com"; // SMTP username
$mail->Password = "mypasswword"; // SMTP password
$Mail->Priority = 1;
$mail->AddAddress("myemail@gmail.com","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.';
}
您没有SMTPSecure设置来定义正在使用的身份验证类型,并且您正在使用不必要的“ssl://”运行主机设置(PS--ssl通过端口465,如果您需要通过ssl运行,请参阅。下面是要添加/更改的行:
+ $mail->SMTPSecure = 'tls';
- $mail->Host = "ssl://smtp.gmail.com";
+ $mail->Host = "smtp.gmail.com";
您是否在本地主机上运行?是否编辑了
php.ini
如果还没有,请尝试以下操作:1.打开xampp->php->php.ini
2.搜索
extension=php\u openssl.dll
3.首字母如下所示:extension=php\u openssl.dll
4.删除“;”,它看起来像这样 5.如果找不到
扩展名=php\u openssl.dll
,请添加此行扩展名=php\u openssl.dll
6.然后重新启动Xampp
Goodluck;)您必须已经安装了php_openssl.dll,如果您使用wampserver,搜索并应用php扩展非常简单 在本例中,请更改以下内容:
//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';
然后你收到了一封来自gmail的电子邮件,其中谈到要启用访问不太安全的应用程序的选项
这里
我建议您更改密码并不断加密它在处理PHPMailer时,您应该查看以下列表:
extension=php\u openSSL.dll
来启用openSSL$mail->SMTPSecure='tls'代码>和$mail->Port=587代码>
删除或注释掉该行-
$mail->IsSMTP();
它会对你有用的
我在不同的网站上检查和试验了许多答案,但除了上面的解决方案外,没有任何解决方案。我知道这个问题已经有一段时间了,但我遇到了确切的问题,通过禁用csf.conf上的SMTP_块(我们使用csf作为防火墙)解决了这个问题 要禁用,只需编辑csf.conf并禁用SMTP_块,如下所示:
###############################################################################
# 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"
解决方案是配置gmail首选项,访问不安全的应用程序我收到一封来自谷歌的电子邮件,告诉我有人试图登录你的帐户,是你,我回答是,然后它开始工作,因此如果是这样,请查看你的电子邮件,允许服务器登录你的谷歌帐户转到“登录”,然后“安全”,滚动至底部,然后启用“允许不太安全的应用程序”选项。最近,谷歌推出了一款名为“应用程序密码”的软件。通过为我的邮箱实例创建应用程序密码,为我解决了这个问题
您做得很好。只需检查不同的SMTP端口,如465和系统上的其他端口即可。 要记住的另一件事是允许google帐户访问,否则它会抛出相同的错误。
我已经看了一整天了,唯一做错的是端口号,我刚更改了端口号,它就工作了。为了让它工作,我必须去myaccount.google.com->“连接的应用程序和站点”,并将“允许不太安全的应用程序”打开(在页面底部附近).如果它可以在本地主机上工作,但不能在web主机上工作: 一些托管站点。如接受的答案中所述,注释掉行
$mail->IsSMTP();
,可能会使其工作,但这只是禁用SMTP配置,并使用托管站点的电子邮件配置
如果您使用的是GoDaddy,则无法使用其他SMTP发送邮件。我使用的是SiteGround,发现他们只允许从端口25和465进行SMTP访问,并且使用SSL加密类型,因此我将查找您主机的文档并从那里开始
SMTP设置
端口:25或587(某些提供程序阻止端口25)
将应用程序部署到服务器后,我通过更改端口来工作
- 在调试中,它对我起了作用:
$mail->Port=25;
- 在发行版中,它对我有效:
$mail->Port=587;
不要使用IDE进行测试,因为如果您在LOCALHOST中使用LOCALHOST/yourfile.php,则可能不起作用。可能是相同的问题>?或者某些web主机不允许您连接到外部smtp服务器。您是否能够从
LOCALHOST
进行连接?@matic:您是如何解决此错误的?我还面临相同的错误仍然不起作用g、 。生成的错误是“错误:无法连接到服务器:连接超时(110)SMTP connect()失败。”。邮件未发送。邮件程序错误:SMTP Connect()失败。“试着用你一直试图修改的代码编辑你的原始帖子,这样我们就可以完全清楚地知道它现在是什么样子了?”?看起来还是可以解决的…我也有类似的问题。您需要指定SMTPSecure设置。如果使用tls,则需要使用587端口。如果使用ssl,则组合为465。是的,去掉smtp.gmail.com前面的ssl://设置Host
totls://smtp.gmail.com
实现的功能与将主机设置为smtp.gmail.com和SMTPSecure设置为tls完全相同;这只是同一事物的另一种语法。您还可以附加一个端口,如:587
,以设置端口
属性。谢谢,这就是我所需要的谢谢!你的回答是最有帮助的,不那么混乱,而且直截了当!我把头发拔了好几个小时!。对我有效的是在这里选择“打开”选项。我正在使用Mac和Xampp。谢谢百万分之一这对我有用
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->IsSMTP();
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail@gmail.com'; // SMTP username
$mail->Password = 'your pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mail@gmail.com');
$mail->addAddress('mail@gmail.com'); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>