简体   繁体   中英

HTML E-Mail with PHP Displaying as Text

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.

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).

I have tried escaping the HTML ($message) portion, I have tried encoding it with htmlentities() but still cannot figure it out.

<script type="text/javascript" src="http://pervlens.com/newsletters/admin/assets/js/tinymce/jquery.tinymce.min.js"></script>
<script type="text/javascript" src="http://pervlens.com/newsletters/admin/assets/js/tinymce/tinymce.min.js"></script>

<script type="text/javascript">
tinyMCE.init({
        mode : "textareas"
});
</script>

<?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 .=' 

<html>
    <body>
<table border="0" cellpadding="0" cellspacing="0" width="650"  align="center">
  <tr>
   <td><img style="display:block;" src="images/adult-v3_01.png" width="650" height="152" alt="Save 40% - Use Offer Code COMEONANDY"></td>
  </tr>
  <tr>
   <td><table align="left" border="0" cellpadding="0" cellspacing="0" width="650">
      <tr>
       <td><img style="display:block;" src="images/adult-v3_02.png" width="275" height="425" alt=""></td>
       <td width="354" bgcolor="#0a310b" style="text-align:center; vertical-align:middle;">

       <!--START BODY TEXT-->
       <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-top: 5px; padding-left:20px; padding-right:20px;">Hi $$first_name$$,</p>
       <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;">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!</p>
       <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;">Were marking Andy Murrays big day by offering you a <strong>40% discount</strong> for today only. Just enter the offer code <strong>COMEONANDY</strong> on the payment page before midnight tonight to claim your savings.</p>

       <table width="354" align="center"><tr><td align="center"><a title="Upgrade now - Save 40% - Use Offer Code COMEONANDY" href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" target="_blank"><img style="display: block;" src="images/CTA-Upgrade_06.png" alt="Save 40% - Use Offer Code COMEONANDY" /></a></td></tr></table>

              <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;">The<a href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" style="color:#FFFFFF; text-decoration:underline;" target="_blank" title="Save 40%!">$$site_name$$</a> team.</p>

       <!--END BODY TEXT-->

       </td>
       <td><img style="display:block;" src="images/Adult-WimbledonDrop1_04.png" width="21" height="425" alt=""></td>
      </tr>
    </table></td>
  </tr>
  <tr>
   <td><img style="display:block;" src="images/Adult-WimbledonDrop1_05.png" width="650" height="148" alt=""></td>
  </tr>
</table>
</body>
</html>
';

// 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: <'.$cardCodes1[0].'>' . '\r\n';

$headers .= 'From: Pervlens Media <benyates1@gmail.com>' . '\r\n';

if (filter_var($to, FILTER_VALIDATE_EMAIL)) {

// Mail it

mail($to, $subject, $message, $headers);

}

}

/////////////// Reading the data from CSV File end ////////////////

}

?>

<div style="width:1000px;margin:auto;">

<h1>knowAhead E-mail Shooter</h1>

<form method="post" enctype="multipart/form-data">

Upload CSV file<input type="file" name="file_up" />

<br/><br/>Message<textarea name="editor1">

<table border="0" cellpadding="0" cellspacing="0" width="650"  align="center">
  <tr>
   <td><img style="display:block;" src="images/adult-v3_01.png" width="650" height="152" alt="Save 40% - Use Offer Code COMEONANDY"></td>
  </tr>
  <tr>
   <td><table align="left" border="0" cellpadding="0" cellspacing="0" width="650">
      <tr>
       <td><img style="display:block;" src="images/adult-v3_02.png" width="275" height="425" alt=""></td>
       <td width="354" bgcolor="#0a310b" style="text-align:center; vertical-align:middle;">

       <!--START BODY TEXT-->
       <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-top: 5px; padding-left:20px; padding-right:20px;">Hi $$first_name$$,</p>
       <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;">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!</p>
       <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;">We're marking Andy Murray's big day by offering you a <strong>40% discount</strong> for today only. Just enter the offer code <strong>COMEONANDY</strong> on the payment page before midnight tonight to claim your savings.</p>

       <table width="354" align="center"><tr><td align="center"><a title="Upgrade now - Save 40% - Use Offer Code COMEONANDY" href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" target="_blank"><img style="display: block;" src="images/CTA-Upgrade_06.png" alt="Save 40% - Use Offer Code COMEONANDY" /></a></td></tr></table>

              <p style="font-family: arial; font-size: 15px; color: #ffffff; padding-left:20px; padding-right:20px;">The<a href="$$app_url$$/member/my/account/payment/?wldsite=$$site_id$$" style="color:#FFFFFF; text-decoration:underline;" target="_blank" title="Save 40%!">$$site_name$$</a> team.</p>

       <!--END BODY TEXT-->

       </td>
       <td><img style="display:block;" src="images/Adult-WimbledonDrop1_04.png" width="21" height="425" alt=""></td>
      </tr>
    </table></td>
  </tr>
  <tr>
   <td><img style="display:block;" src="images/Adult-WimbledonDrop1_05.png" width="650" height="148" alt=""></td>
  </tr>
</table>

</textarea>

<br/><br/>Upload image<input type="file" name="main_image" /><br/><br/>

<input type="submit" name="submit" value="Submit" />

</form>
</div>

As always any help would be greatly appreciated.

Change '\\r\\n' to "\\r\\n" in all your assignments to $headers . Escape sequences are only interpreted in doublequoted strings not singlequoted strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM