title: PHP Mailer with HTML template and sending variables
body: <p>Basically I'm trying to do this.</p>
  
  <p><a href="http://www.xeweb.net/2009/12/31/sending-emails-the-right-way-using-phpmailer-and-email-templates/" rel="noreferrer">http://www.xeweb.net/2009/12/31/sending-emails-the-right-way-using-phpmailer-and-email-templates/</a></p>
  
  <p>Here is my code</p>
  
  <h1>index.php</h1>
  
  <pre><code>    &lt;?php 
      include('class.phpmailer.php'); // Retrieve the email template required 
      $message = file_get_contents('mail_templates/sample_mail.html'); 
      $message = str_replace('%testusername%', $username, $message); 
      $message = str_replace('%testpassword%', $password, $message); 
      $mail = new PHPMailer(); $mail-&gt;IsSMTP(); // This is the SMTP mail server 
  
      $mail-&gt;SMTPSecure = 'tls';
      $mail-&gt;Host = "smtp.gmail.com";
      $mail-&gt;Port = 587; 
      $mail-&gt;SMTPAuth = true; 
      $mail-&gt;Username = 'mygmailid@gmail.com'; 
      $mail-&gt;Password = 'mypassword'; 
      $mail-&gt;SetFrom('fromgmail@gmail.com', 'Pricol Technologies'); 
      $mail-&gt;AddAddress('addaddress@gmail.com'); 
      $mail-&gt;Subject = 'Your account information';
      $mail-&gt;MsgHTML($message);
      $mail-&gt;IsHTML(true); 
      $mail-&gt;CharSet="utf-8";
      //$mail-&gt;AltBody(strip_tags($message)); 
      if(!$mail-&gt;Send()) {  
      echo "Mailer Error: " . $mail-&gt;ErrorInfo;
      } 
      ?&gt;
  </code></pre>
  
  <h1>mail_templates/sample_mail.html</h1>
  
  <pre><code>    &lt;html&gt;
      &lt;body&gt;
      &lt;h1&gt;Account Details&lt;/h1&gt;
      &lt;p&gt;Thank you for registering on our site, your account details are as follows:&lt;br&gt;
      Username: %username%&lt;br&gt;
      Password: %password% &lt;/p&gt;
      &lt;/body&gt;
      &lt;/html&gt; 
  </code></pre>
  
  <p>I'm getting the mail as follows:</p>
  
  <pre><code>    Account Details
  
      Thank you for registering on our site, your account details are as follows:
      Username: %testusername%
      Password: %testpassword%    
  </code></pre>
  
  <h1>Expected Output</h1>
  
  <pre><code>        Account Details
  
          Thank you for registering on our site, your account details are as follows:
          Username: testusername
          Password: testpassword
  </code></pre>
  
  <p>Where did I went wrong. I have checked some forum. But no use.</p>
  
  <p>I have previously asked some question. But my project requirement is to have the html template with % variable name % so that anyone could make changes in the html file without touching the code part.</p>