PHP Mailer Class issue :Message body empty

2020-02-07 04:03发布

When i try to send email using PHPMailer class I get this error : Mailer Error: Message body empty :

<?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!";
    }
?>

标签: php
3条回答
等我变得足够好
2楼-- · 2020-02-07 04:15

This post has been mentioned in the past here. Phpmailer sending attachments, but not the body

They found that they could not send the body and the attachments.

查看更多
ら.Afraid
3楼-- · 2020-02-07 04:17

As Gerald Versluis said, since you're setting IsHTML() to false, you'll have to use the ->Body property to set the actual body of the mail.

$mail->Body = $_GET['msg'];

You should also use POST instead of GET for submitting something which causes an action to be performed.

查看更多
一纸荒年 Trace。
4楼-- · 2020-02-07 04:19

I had these two lines of code but didn't have any contents.html file and I had to create one in order to avoid the error.

//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';`
查看更多
登录 后发表回答