linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误
转自:https://www.cnblogs.com/raincowl/p/8875647.html
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = ;
//Set the hostname of the mail server
$mail->Host = 'smtp.qq.com';
//$mail->Host = 'smtp.163.com';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = ;
$mail->SMTPSecure = "ssl";
//$mail->SMTPAuth = false;
//$mail->SMTPSecure = false;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = 'xxxxxxx@qq.com';
//$mail->Username = 'raincowl@163.com';
//Password to use for SMTP authentication
//$mail->Password = 'lingshuan008';
$mail->Password = 'password';
//Set who the message is to be sent from
//$mail->setFrom('raincowl@163.com', 'fromuser');
$mail->setFrom('xxxxxxx@qq.com', 'fromuser');
//Set an alternative reply-to address
//$mail->addReplyTo('raincowl@163.com', 'First Last');
$mail->addReplyTo('xxxxxxx@qq.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('yyyyyyy@qq.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
$mail->msgHTML('hello,body!');
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png'); //send the message, check for errors
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}
首先本地windows下,发送成功,很happy,那就放上linux上试下,一运行,出现
SMTP ERROR: Failed to connect to server: ()
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
然后各大技术论坛查资料;首先检查linux服务器上的openssl和sockets已经开启,fsockopen函数也没有禁用,邮箱的smtp服务也已经开启,依然还是不行。至于有一种说法将smtp换成SMTP,是能够发送成功,后来查看下源码,发现这种只是通过sendmail发送的,不是smtp。然后,直接在linux上ping smtp.qq.com,telnet smtp.qq.com 465都没什么问题,可是依然发送报上述的错误,后来查看官网资料,发现下面一段代码
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
将这段代码加上之后,邮件发送成功。
linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误的更多相关文章
- phpmailer的SMTP ERROR: Failed to connect to server: 10
请问,我在win7上学习使用phpmailer时,出现这种错误怎么处理啊? SMTP ERROR: Failed to connect to server: (0) SMTP connect() fa ...
- 使用phpmailer插件发邮件失败提示:SMTP -> ERROR: Failed to connect to server: Connection timed out (110) smtp connect() failed;
一个邮件发送问题,整整弄了我一周时间,起因是这样的,之前弄的一个网站,需要在邮箱里面认证之后才可以注册成功.网站上线了差不多一年之后,客户突然跟我说,网站不能注册了,然后我就查看了一下代码. 发现报这 ...
- 用phpmailer发送邮件提示SMTP Error: Could not connect to SMTP host解决办法
之前做项目的时候做了一个用phpmailer发送邮件的功能<CI框架结合PHPmailer发送邮件>,昨天步署上线(刚开始用新浪云,嫌贵,换成阿里了),测试的时候,发送邮件却意外报错了.. ...
- 腾讯云服务器SMTP ERROR: Failed to connect to server
一般邮件发送失败是 1.配置的问题. 2.扩展问题socket/ssl 百度搜出来一般都是以上的解决办法, 但是我这次遇到的不是. 本地可以放到腾讯云服务器就不行了,扩展也都开了. 后来发现是安全组端 ...
- Linux下安装vim-plug报错:Failed to connect to raw.githubusercontent.com port 443: Connection refused
安装vim-plug时,输入以下命令: curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.c ...
- linux下安装svn出现configure: error: We require OpenSSL; try --with-openssl
linux下安装svn出现configure: error: We require OpenSSL; try --with-openssl http://blog.csdn.net/woshixion ...
- phpmailer SMTP Error: Could not connect to SMTP host. 错误解决
今天发邮件遇到了这么一个问题:SMTP Error: Could not connect to SMTP host.在网上找了好多,都不管用.在这里我要提醒大家下 1.确保发送者邮箱密码正确,代码编写 ...
- GConf error:Failed to contact configuration server
Linux系统运行一直正常,但是图形界面使用root账号登录时遇到下面错误,第一次遇到这么怪异的状况 具体错误信息如下所示: GConf error:Failed to contact configu ...
- error: failed to connect to the hypervisor error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory 解决办法
服务器版本:CentOS Linux release 7.4 Linux lb 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x8 ...
随机推荐
- 彻底终结MySQL同步延迟问题
作为一名DBA,在工作中会经常遇到一些MySQL主从同步延迟的问题,这些同步慢的问题,其实原因非常多,可能是因为主从的网络问题导致,可能是因为网络带宽问题导致,可能是因为大事务导致,也可能是因为单线程 ...
- ASP.NET Core 2.2 项目升级至 3.0 备忘录
将 ASP.NET Core 2.2 迁移至 ASP.NET Core 3.0 需要注意的地方记录在这篇随笔中. TargetFramework 改为 netcoreapp3.0 <Target ...
- 用java刷剑指offer(二叉树中和为某一值的路径)
题目描述 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长度大 ...
- 大数据之路week07--day05 (一个基于Hadoop的数据仓库建模工具之一 HIve)
什么是Hive? 我来一个短而精悍的总结(面试常问) 1:hive是基于hadoop的数据仓库建模工具之一(后面还有TEZ,Spark). 2:hive可以使用类sql方言,对存储在hdfs上的数据进 ...
- 《Exception》第五次作业:项目需求分析改进与系统设计
一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 1掌握面向对象需求分析方法:2.学习软件系统总 ...
- SpringBoot官方文档学习(三)配置文件、日志、国际化和JSON
一.Profiles Spring配置文件提供了一种方法来隔离应用程序配置的各个部分,并使其仅在某些环境中可用.任何@Component.@Configuration或@ConfigurationPr ...
- PHP流程控制之do...while循环的区别
do...while与while的语法结构基本一样,也是一个布尔型循环,功能也基本一样.大理石平台价格 基本语法规定如下: do { //代码块 } while (判断); do...while ...
- ashx 图片上传路径URL
ashx 图片上传 为了方便多出调用图片上传方法 首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collection ...
- regedit系统注册表,msconfig系统配置
msconfig msconfig即系统配置实用程序,是Microsoft System Configuration的缩写.是在开始菜单里运行中输入然后确认就可以找到程序开启或者禁用, 可以帮助电脑禁 ...
- aix 10代oracle zabbix2.4.4 日志监控
同一类型的监控项,zabbix 2.4的客户端也支持日志监控,可是在参数个数上有问题,如果把所有参数都放满,监控项会提示too mant parameters,无法 生效取数据, 对于不同的正则式.m ...