Send html emails using PHPMailer and html templates
<p>I'm trying to get the emails sent from my contact (using PHPMailer) sent in a nice html template (phtml actually).</p>

<p>What works: I receive the html template so no issue with the transmission</p>

<p>What does <strong>not</strong> work: The variables (message, phone number, etc) are not reflected in the body of my html template.
I have tried several things in the html template, without success: <code>&lt;?= htmlspecialchars($message) ?&gt;</code> and <code>#message#</code> and <code>&lt;?php echo$_POST['message'] ?&gt;</code></p>

<p>What is the issue?</p>

<p>Thanks,</p>

<p>Here is the PHPMailer code:</p>

<pre><code>&lt;?php

require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail-&gt;CharSet = 'utf-8';
$body = file_get_contents('htmlemail.phtml');

//Enable SMTP debugging. 
$mail-&gt;SMTPDebug = false;                               
//Set PHPMailer to use SMTP.
$mail-&gt;isSMTP();            
//Set SMTP host name                          
$mail-&gt;Host = "smtp.sendgrid.net";
//Set this to true if SMTP host requires authentication to send email
$mail-&gt;SMTPAuth = true;                          
//Provide username and password     
$mail-&gt;Username = "";                 
$mail-&gt;Password = "";                           
//If SMTP requires TLS encryption then set it
$mail-&gt;SMTPSecure = "tls";                           
//Set TCP port to connect to 
$mail-&gt;Port = 587;                                   

$mail-&gt;From = $_POST['email'];
$mail-&gt;FromName = $_POST['first_name'] . " " . $_POST['last_name'];

$mail-&gt;addAddress("@gmail.com");
//CC and BCC
$mail-&gt;addCC("");
$mail-&gt;addBCC("");

$mail-&gt;isHTML(true);

$mail-&gt;Subject = "Nouveau message depuis ";

$mail-&gt;MsgHTML($body);



$response = array();
if(!$mail-&gt;send()) {
  $response = array('message'=&gt;"Mailer Error: " . $mail-&gt;ErrorInfo, 'status'=&gt; 0);
} else {
  $response = array('message'=&gt;"Message has been sent successfully", 'status'=&gt; 1);
}

/* send content type header */
header('Content-Type: application/json');

/* send response as json */
echo json_encode($response);

?&gt;
</code></pre>