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
微信打赏
支付宝打赏
感谢您对作者ada的打赏,我们会更加努力! 如果您想成为作者,请点我