邮件发送过程中,错误可能有很多,文件未包裹的空白字符、邮箱平台都可能导致程序莫名崩溃,我的建议是不要用QQ邮箱,试一下126邮箱。
这是我之前测试通过的代码:
function sendMail($address,$title,$content){
require("./PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.126.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "roadcover@126.com"; // SMTP username
$mail->Password = "wangyi126"; // SMTP password
$mail->From = "roadcover@126.com";
$mail->FromName = "Mailer";
$mail->AddAddress($address); // name is optional
//$mail->AddReplyTo("info@example.com", "Information");
//$mail->WordWrap = 50; // set word wrap to 50 characters
//$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->CharSet='UTF-8';
$mail->Subject = $title;
$mail->Body = $content;
//$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;
exit;
}
echo "Message has been sent";
}
sendMail("roadcover@126.com","测试",'hello,world');
?>
你简单改一下代码即可,仅注意:$mail->Password 的密码不是指邮箱登陆密码,是指登陆后STMP认证密码,如果对你有帮助,请为我点个赞:),谢谢。