title: HTML E-Mail with PHP Displaying as Text
body: <p>I'm having problems with the following code. i have it sending the HTML message but every test I have sent comes through as text, I need HTML.</p>
  
  <p>The purpose of this script is to allow a pre-formatted/created html e-mail template be sent a bunch of e-mail addresses uploaded via a CSV file. It's meant to be quick and dirty for a bunch of one off e-mails to a handful of affiliates (e-mail addresses given for this purpose).</p>
  
  <p>I have tried escaping the HTML ($message) portion, I have tried encoding it with htmlentities() but still cannot figure it out.</p>
  
  <pre><code>&lt;script type="text/javascript" src="http://pervlens.com/newsletters/admin/assets/js/tinymce/jquery.tinymce.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://pervlens.com/newsletters/admin/assets/js/tinymce/tinymce.min.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  tinyMCE.init({
          mode : "textareas"
  });
  &lt;/script&gt;
  
  &lt;?php
  
  if(isset($_POST['submit'])){
  
  $input_filename = $_FILES['file_up']['tmp_name'];
  
  $input_filesize = filesize($input_filename);
  
  if (($handle = fopen($input_filename, 'r')) === FALSE) {
  
  die('Error opening file');
  
  }
  
  /////////////// Reading the data from CSV File ///////////////////
  
  //$headers = fgetcsv($handle, $input_filesize, ‘,’);
  
  $cardCodes = array();
  
  while ($row = fgetcsv($handle, $input_filesize, ',')) {
  
  $cardCodes[] = $row;
  
  }
  
  // message
  
  $message .=' 
  
  &lt;html&gt;
      &lt;body&gt;
  &lt;table border="0" cellpadding="0" cellspacing="0" width="650"  align="center"&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;img style="display:block;" src="images/adult-v3_01.png" width="650" height="152" alt="Save 40% - Use Offer Code COMEONANDY"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;table align="left" border="0" cellpadding="0" cellspacing="0" width="650"&gt;
        &lt;tr&gt;
         &lt;td&gt;&lt;img style="display:block;" src="images/adult-v3_02.png" width="275" height="425" alt=""&gt;&lt;/td&gt;
         &lt;td width="354" bgcolor="#0a310b" style="text-align:center; vertical-align:middle;"&gt;
  
         &lt;!--START BODY TEXT--&gt;
         &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-top: 5px; padding-left:20px; padding-right:20px;"&gt;Hi $$first_name$$,&lt;/p&gt;
         &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;"&gt;Its the Wimbledon mens final today so fans will be celebrating a great spectacle of sport, and non-fans will just be celebrating BBC2 getting back to normal service tomorrow!&lt;/p&gt;
         &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;"&gt;Were marking Andy Murrays big day by offering you a &lt;strong&gt;40% discount&lt;/strong&gt; for today only. Just enter the offer code &lt;strong&gt;COMEONANDY&lt;/strong&gt; on the payment page before midnight tonight to claim your savings.&lt;/p&gt;
  
         &lt;table width="354" align="center"&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;a title="Upgrade now - Save 40% - Use Offer Code COMEONANDY" href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" target="_blank"&gt;&lt;img style="display: block;" src="images/CTA-Upgrade_06.png" alt="Save 40% - Use Offer Code COMEONANDY" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  
                &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;"&gt;The&lt;a href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" style="color:#FFFFFF; text-decoration:underline;" target="_blank" title="Save 40%!"&gt;$$site_name$$&lt;/a&gt; team.&lt;/p&gt;
  
         &lt;!--END BODY TEXT--&gt;
  
         &lt;/td&gt;
         &lt;td&gt;&lt;img style="display:block;" src="images/Adult-WimbledonDrop1_04.png" width="21" height="425" alt=""&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;img style="display:block;" src="images/Adult-WimbledonDrop1_05.png" width="650" height="148" alt=""&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ';
  
  // message end
  
  foreach($cardCodes as $cardCodes1){
  
  // multiple recipients
  
  $to  = $cardCodes1[0];
  
  // subject
  
  $subject = 'Your company name  newsletter';
  
  // To send HTML mail, the Content-type header must be set
  
  $headers  = 'MIME-Version: 1.0' . '\r\n';
  
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
  
  // Additional headers
  
  $headers .= 'To: &lt;'.$cardCodes1[0].'&gt;' . '\r\n';
  
  $headers .= 'From: Pervlens Media &lt;benyates1@gmail.com&gt;' . '\r\n';
  
  if (filter_var($to, FILTER_VALIDATE_EMAIL)) {
  
  // Mail it
  
  mail($to, $subject, $message, $headers);
  
  }
  
  }
  
  /////////////// Reading the data from CSV File end ////////////////
  
  }
  
  ?&gt;
  
  &lt;div style="width:1000px;margin:auto;"&gt;
  
  &lt;h1&gt;knowAhead E-mail Shooter&lt;/h1&gt;
  
  &lt;form method="post" enctype="multipart/form-data"&gt;
  
  Upload CSV file&lt;input type="file" name="file_up" /&gt;
  
  &lt;br/&gt;&lt;br/&gt;Message&lt;textarea name="editor1"&gt;
  
  &lt;table border="0" cellpadding="0" cellspacing="0" width="650"  align="center"&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;img style="display:block;" src="images/adult-v3_01.png" width="650" height="152" alt="Save 40% - Use Offer Code COMEONANDY"&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;table align="left" border="0" cellpadding="0" cellspacing="0" width="650"&gt;
        &lt;tr&gt;
         &lt;td&gt;&lt;img style="display:block;" src="images/adult-v3_02.png" width="275" height="425" alt=""&gt;&lt;/td&gt;
         &lt;td width="354" bgcolor="#0a310b" style="text-align:center; vertical-align:middle;"&gt;
  
         &lt;!--START BODY TEXT--&gt;
         &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-top: 5px; padding-left:20px; padding-right:20px;"&gt;Hi $$first_name$$,&lt;/p&gt;
         &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;"&gt;It's the Wimbledon men's final today so fans will be celebrating a great spectacle of sport, and non-fans will just be celebrating BBC2 getting back to normal service tomorrow!&lt;/p&gt;
         &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;"&gt;We're marking Andy Murray's big day by offering you a &lt;strong&gt;40% discount&lt;/strong&gt; for today only. Just enter the offer code &lt;strong&gt;COMEONANDY&lt;/strong&gt; on the payment page before midnight tonight to claim your savings.&lt;/p&gt;
  
         &lt;table width="354" align="center"&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;a title="Upgrade now - Save 40% - Use Offer Code COMEONANDY" href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" target="_blank"&gt;&lt;img style="display: block;" src="images/CTA-Upgrade_06.png" alt="Save 40% - Use Offer Code COMEONANDY" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  
                &lt;p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;"&gt;The&lt;a href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" style="color:#FFFFFF; text-decoration:underline;" target="_blank" title="Save 40%!"&gt;$$site_name$$&lt;/a&gt; team.&lt;/p&gt;
  
         &lt;!--END BODY TEXT--&gt;
  
         &lt;/td&gt;
         &lt;td&gt;&lt;img style="display:block;" src="images/Adult-WimbledonDrop1_04.png" width="21" height="425" alt=""&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;img style="display:block;" src="images/Adult-WimbledonDrop1_05.png" width="650" height="148" alt=""&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/textarea&gt;
  
  &lt;br/&gt;&lt;br/&gt;Upload image&lt;input type="file" name="main_image" /&gt;&lt;br/&gt;&lt;br/&gt;
  
  &lt;input type="submit" name="submit" value="Submit" /&gt;
  
  &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As always any help would be greatly appreciated.</p>