当我尝试使用PHPMailer类发送电子邮件时,我会收到以下错误:Mailer错误:邮件正文为空:
<?php
include("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "rsb20.rhostbh.com";
$mail->Port = 465;
$mail->Username = "jobserreker+furrtexlab.com";
$mail->Password = "12345678a";
$mail->From = "jobserreker@furrtexlab.com";
$mail->FromName = "Job Seeker";
$mail->Subject = $_GET['subject'];
$mail->MsgHTML($_GET['msg']);
$mail->AddAddress($_GET['to'],"name to");
$mail->IsHTML(false);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
?>
正如Gerald Versluis所说,由于您将IsHTML()设置为false,因此必须使用->Body属性来设置邮件的实际正文。
$mail->Body = $_GET['msg'];
您还应该使用POST而不是GET来提交导致执行操作的内容。
这篇文章过去曾在这里提到过。Phpmailer发送附件,但不发送正文
他们发现无法发送尸体和附件。
我有这两行代码,但没有任何contents.html文件,为了避免错误,我不得不创建一个。
//Read an HTML message body from an external file, convert referenced imagesto embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';`