0

I feel embarassed to ask this because I have seen this question asked several times. However none of the solutions seem to be working for me. My HTML is output as plain text in the body of e-mail sent through PHPMailer

I have read the PHPMailer documentation on Github and found answers like this PHPmailer sending HTML CODE and this Add HTML formatting in phpmailer on stackoverflow.

    //Create a new PHPMailer instance
    $mail = new PHPMailer(true);
    // Set PHPMailer to use the sendmail transport
    $mail->isSendmail();
    //Set who the message is to be sent from
    $mail->setFrom('xxx@yyy.com');
    //Set an alternative reply-to address
    //    $mail->addReplyTo('replyto@example.com', 'First Last');
    //Set who the message is to be sent to
    $mail->addAddress('xxx@yyy.com');
    //Set the subject line
    $mail->Subject = 'Rework Report';

    $body = file_get_contents('current/rework.txt');
    $mail->Body= $body;
    $mail->IsHTML = (true);

   //Attach a file
   //$mail->addAttachment('current/rework.txt');
   //send the message, check for errors
   if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }

The output should be HTML in the body of the e-mail.

Scott
  • 11
  • 3
  • You're fetching the content of a `.txt` file that contains HTML? Why are you using `isSendmail()`? It's very unlikely you need to do that. – Synchro Jan 09 '19 at 16:53
  • You're also enabling exceptions without a try/catch block. Are you using an old version of PHPMailer? – Synchro Jan 09 '19 at 17:01

1 Answers1

1

As per the PHPmailer sending HTML CODE link in your question, you likely need to change:

// From
$mail->IsHTML = (true);
// To -- i.e. remove the equals sign (=)
$mail->IsHTML(true);

As it appears to be a function as opposed to a variable.

seantunwin
  • 1,364
  • 12
  • 14