测试邮件:Mailer Error: SMTP connect() failed.

zhaozhiqiang000 2016-01-19 04:51:04
在https://github.com/PHPMailer/PHPMailer/上找的PHPMailer类,挺强大,


header("Content-Type:text/html;charset=utf-8");
require 'Study/PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3; // Enable verbose debug output

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.163.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'my163@163.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'SSL'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to

$mail->setFrom('my163@163.com', 'Mailer');
$mail->addAddress('my163@163.com', 'Joe User'); // Add a recipient
$mail->addAddress('myqq@qq.com'); // Name is optional
$mail->addReplyTo('my163@163.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}

出现错误:
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

php.ini的openSSL已经打开,apache重启,引入的类库路径正确,参考http://stackoverflow.com/questions/30542095/mailer-error-smtp-connect-failed-in-php-mailer-https-github-com-phpmailer的解决方法也不行,实在找不到原因,问问这里的大神
...全文
4934 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangyihui802321 2017-08-10
  • 打赏
  • 举报
回复
我的也出现了同样的问题,也是在网上看了许多,也是没有解决。 但是后来重新到网易邮箱上对客户端密码进行了设置,打开了POP3/SMTP服务就可以了。(小贴士psw用的是客户端授权密码)
Code_Lyoko 2016-11-21
  • 打赏
  • 举报
回复
请问楼主搞定了么? 我的在WIN本地测试163的25端口可以发送邮件。 在centos 6.5上不行,但是qq邮箱可以。 不知道什么情况,也是这歌错误。
码无边 2016-01-20
  • 打赏
  • 举报
回复
1.检查下你的php扩展ssl和socket是否开启。 2.查看邮件服务器的端口是否正确。
zhaozhiqiang000 2016-01-20
  • 打赏
  • 举报
回复
引用 1 楼 zy205817 的回复:
1.检查下你的php扩展ssl和socket是否开启。 2.查看邮件服务器的端口是否正确。
php扩展ssl和socket已开启, 163的服务器端口25,加密SSL是456/587,正确

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧