PHPmailer sending HTML CODE

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 **


Solution 1:

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.

Solution 2:

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)

Solution 3:

or if you have still problems you can use this

$mail->Body =  html_entity_decode($Body);