phpmailer php7,Phpmailer—踩过的坑【原创】

本文主要介绍了使用PHPMailer发送邮件时遇到的错误,如连接失败(Selinux权限问题)和认证失败(密码错误或授权码问题)。针对这些问题,提供了解决方案,如修改Selinux规则和正确配置SMTP服务器的用户名、密码和端口。同时,文章还提到了邮件内容乱码的解决办法,通过设置字符集和编码方式确保邮件正文正常显示。
摘要由CSDN通过智能技术生成

PHPMailer是一个用于发送电子邮件的PHP函数包。直接用PHP就可以发送,无需搭建复杂的Email服务。

这里列出使用phpmaile中碰到的问题,同时也欢迎大家补充

连接失败:出现以下情况

2018-01-09 14:05:00 Connection: opening to smtp.exmail.qq.com:25, timeout=300, options=array ( ) 2018-01-09 14:05:00 SMTP ERROR: Failed to connect to server: Permission denied (13) 2018-01-09 14:05:00 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我用的是centos,这是因为selinux拒绝httpd服务发送邮件, 可以修改selinux的规则。

getsebool -a  | grep httpd_can_sendmail(查看)

setsebool -P httpd_can_sendmail 1(重新设置,允许发邮件)

认证失败(密码认证失败)

填写的密码不是登录的密码,二是第三方授权码

邮件接收方不合法

29 06:41:56 SMTP ERROR: MAIL FROM command failed: 553 Mail from must equal authorized user

接收邮件的地址不合法

发的邮件乱码(标题,简介,内容乱码)

$mail = new PHPMailer;

$mail->Charset='UTF-8';

$mail->Encoding = "base64";//设置文本编码方式

$mail->isSMTP();

$mail->SMTPDebug = 2;

//Set the hostname of the mail server

$mail->Host = 'smtp.126.com';

$mail->Port = 465;

//Set the encryption system to use - ssl (deprecated) or tls

$mail->SMTPSecure = 'ssl';

//Whether to use SMTP authentication

$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail

$mail->Username = "abc@126.com";

//Password to use for SMTP authentication

$mail->Password = "******"; // 授权码

//Set who the message is to be sent from

$mail->setFrom(abc @126.com', "=?utf-8?B?".base64_encode("授权码")."?=");

$mail->addAddress($addEmail);

$mail->Subject = "=?utf-8?B?" . base64_encode("提醒:您有消息") . "?=";

$mail->msgHTML("授权码授权码授权码");

$mail->AltBody = 'This is a plain-text message body';

if (!$mail->send()) {

return "Mailer Error: " . $mail->ErrorInfo;

} else {

return "Message sent!";

}

return new Response();

转载时请注明出处及相应链接,本文永久地址:https://blog.yayuanzi.com/23292.html

75d087ef9a9fb11dc373caaf33adbf7f.png

微信打赏

支付宝打赏

感谢您对作者ada的打赏,我们会更加努力!    如果您想成为作者,请点我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值