PHPMailer配置QQ邮箱
2019-01-22phpmailer配置qq邮箱,发送邮件总是不成功,一直以为密码就是邮箱密码,登陆邮箱也没问题,开启smtp验证时候,发现密码不一样。
1、邮件发送失败.
错误原因: SMTP Error: Could not authenticate.
2、SMTP server error: Error: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
3、实例
<?php
$username = $_GET['username'];
$email = $_GET['email'];
$session_code = $_GET['session_code'];
require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录
require("class.smtp.php"); //下载的文件必须放在该文件所在目录
$mail = new PHPMailer(); //建立邮件发送类
$mail->CharSet="utf-8";
$mail->Encoding = "base64";
$address ="$email";
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->SMTPAuth = true; // 启用SMTP验证功能
$mail->SMTPKeepAlive = true;
$mail->SMTPSecure= "ssl";
$mail->Host = "smtp.qq.com"; // 您的企业邮局域名
$mail->Username = "9239604@qq.com"; // 邮局用户名(请填写完整的email地址)
$mail->Password = "q2sww1tskrp1egibixx"; // 邮局密码
$mail->Port=465;
$mail->From = "9239604@qq.com"; //邮件发送者email地址
$mail->FromName = "test";
$mail->AddAddress("$address", substr($email,0,strrpos($email,'.')));//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
//$mail->AddReplyTo("", "");
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式
$mail->Subject = "test"; //邮件标题
$content = '亲爱的'.$username.':<br>'.
(这是一封自动产生的email,请勿回复。)<br>';
$mail->Body = $content; //邮件内容
$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
if(!$mail->Send())
{
echo "邮件发送失败. <p>";
echo "错误原因: " . $mail->ErrorInfo;
exit;
}
echo "true";
exit;
?>