29

I am using PHPmailer to send email.

I have also used HTML = True content type

    $mail = new PHPMailer();

$mail->IsSMTP();                    // send via SMTP
$mail->Host     = $Host; 
$mail->SMTPAuth = true;             // turn on SMTP authentication
$mail->Username = $Username;  
$mail->Password = $Password; 

$mail->From     = $From;
$mail->FromName = $FromName;

    $mail->AddAddress($To , $ToName);

$mail->WordWrap = 50;               // set word wrap
    $mail->Priority = 1; 
$mail->IsHTML(true);  
$mail->Subject  =  $Subject;
$mail->Body     =  $Body;

Once the email is sent i see the actual HTML code instead of the contents please check below

enter image description here

**Not sure what is the issue **

user580950
  • 3,178
  • 12
  • 42
  • 80

7 Answers7

76

Calling the isHTML() method after the instance Body property (I mean $mail->Body) has been set solved the problem for me:

$mail->Subject = $Subject;
$mail->Body    = $Body;
$mail->IsHTML(true);       // <=== call IsHTML() after $mail->Body has been set.
Nabil Kadimi
  • 8,870
  • 2
  • 46
  • 54
  • That is correct but you should never call `$mail->ClearCustomHeaders();` after `$mail->IsHTML(true)`. `ClearCustomHeader` gets rid of your email HTML formatting and instead recipient will receive HTML source code. – Junior Mayhé Oct 13 '15 at 15:25
  • 2
    personally I use: $mail->msgHTML($email_body); – Dimi Jun 08 '18 at 13:10
8

There is msgHTML() method, which also call IsHTML().

The name IsHTML is confusing...

/**
 * Create a message from an HTML string.
 * Automatically makes modifications for inline images and backgrounds
 * and creates a plain-text version by converting the HTML.
 * Overwrites any existing values in $this->Body and $this->AltBody
 * @access public
 * @param string $message HTML message string
 * @param string $basedir baseline directory for path
 * @param bool $advanced Whether to use the advanced HTML to text converter
 * @return string $message
 */
public function msgHTML($message, $basedir = '', $advanced = false)
SwissCodeMen
  • 2,397
  • 3
  • 12
  • 21
Atombit
  • 654
  • 7
  • 10
3

or if you have still problems you can use this

$mail->Body =  html_entity_decode($Body);
Prahalad Gaggar
  • 10,486
  • 16
  • 46
  • 66
adq82
  • 29
  • 1
0

In version 5.2.7 I use this to send plain text:

$mail->set('Body', $Body);
SwissCodeMen
  • 2,397
  • 3
  • 12
  • 21
Mladen Janjetovic
  • 11,254
  • 8
  • 64
  • 74
-1

just you need to pass true as an argument to IsHTML() function.

-2

do like this-paste your html code inside your separate html file using GET method.

$mail->IsHTML(true);                                 
    $mail->WordWrap = 70;                                 
    $mail->addAttachment= $_GET['addattachment']; $mail->AltBody   
    =$_GET['AltBody'];  $mail->Subject = $_GET['subject']; $mail->Body = $_GET['body'];
shailendra pathak
  • 612
  • 1
  • 7
  • 25
-2

all you need to do is just add $mail->IsHTML(true); to the code it works fine..

odide
  • 1