PHP邮件发送类问题:邮件正文为空。

3
当我尝试使用PHPMailer类发送电子邮件时,出现以下错误: 邮件程序错误:消息正文为空:
<?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!";
    }
?>

$_GET ['msg'] 是否为空的可能性有多大? - unfrev
1
如果您使用 $mail->MsgHTML($_GET['msg']); 但随后说 $mail->IsHTML(false);,那么您是否应该使用另一个属性来设置文本?像 Body 这样的属性?或者 $_GET['msg'] 是空的吗? - Gerald Versluis
请执行以下代码 echo '--->' . $_GET['msg'] . '<---',以检查 $_GET['msg'] 的内容。 - fsenart
你如何访问网站中的这个页面?使用哪个带有查询字符串的URL?通过检查查询字符串,我们可以更多地了解$_GET['msg']为空的原因。 - fsenart
3个回答

5
正如Gerald Versluis所说,因为您将IsHTML()设置为false,所以必须使用->Body属性来设置邮件的实际正文。
$mail->Body = $_GET['msg'];

在提交需要执行某个操作的内容时,应该使用POST而不是GET。


这个也不行。有些消息已经发送了,但是没有得到响应。 - Aan
1
当您收到邮件时,请添加var_dump($mail),并在您的问题中发布结果。检查抛出消息只是执行if(empty($this->Body)),所以我猜想您没有将其设置为您认为的值(或调用其他重置->Body的内容)。 - MatsLindh

0
我有这两行代码,但没有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';`

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接