SMTPError:CouldnotconnecttoSMTPhost.该如何解决
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了SMTPError:CouldnotconnecttoSMTPhost.该如何解决,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1988字,纯文字阅读大概需要3分钟。
内容图文
![SMTPError:CouldnotconnecttoSMTPhost.该如何解决](/upload/InfoBanner/zyjiaocheng/221/1e86a15f532643f493bc0616a09761df.jpg)
我用网页运行时正常,能发送,用命令运行php文件时报错,主要代码经检查无误,如下
function sendmail($setEmail, $setName, $body, $subject) {输出错误的)
require_once("PHPMail/phpmailer.php");
$mail = new PHPMailer ( true ); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP (); // telling the class to use SMTP
try {
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = SBT_SSL; // sets the prefix to the servier
$mail->Host = SBT_SMTP_HOST; // sets GMAIL as the SMTP server
$mail->Port = SBT_SMTP_PORT; // set the SMTP port for the GMAIL server
$mail->Username = SBT_SMTP_USER; // GMAIL username
$mail->Password = SBT_SMTP_PASS; // GMAIL password
$mail->AddReplyTo ( SBT_MAIL_FROM, SBT_MAIL_FROM_NAME );
$mail->AddAddress ( $setEmail, $setName );
$mail->SetFrom (SBT_SMTP_USER,SBT_SMTP_USER); //sender name
$mail->Subject = $subject;
$mail->MsgHTML ( $body );
if (! $mail->Send ()) {//(这边没报错)
echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;
exit ();
}
} catch ( phpmailerException $e ) {
echo $e->errorMessage (); //Pretty error messages from PHPMailer(就是这边
} catch ( Exception $e ) {
echo $e->getMessage (); //Boring error messages from anything else!
}
}
问下是什么原因,目的是为了可以用linux计划任务来执行该PHP文件
------解决方案--------------------
错误代码呢?
------解决方案--------------------
php --ini 一下,看使用的ini是否和作为apache模块运行的php一致.
------解决方案--------------------
不可能,$mail->IsSMTP ();这个表明你已经设置了smtp发送了.
你现在的主要问题是找找看为什么socket连接不了smtp服务器.
防火墙也有可能.
------解决方案--------------------
wamp环境,应该是共用一份ini文件的.想再一次确定的话,php网页输出phpinfo(),看使用的ini文件,是否和这个一致.
命令:telnet smtp.gmail.com 465 ,确定能连接成功?
------解决方案--------------------
检查一下防火墙,另外再检查一下发送图片附件的代码
------解决方案--------------------
telnet都不行,肯定是你防火墙禁止了访问
内容总结
以上是互联网集市为您收集整理的SMTPError:CouldnotconnecttoSMTPhost.该如何解决全部内容,希望文章能够帮你解决SMTPError:CouldnotconnecttoSMTPhost.该如何解决所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。