PHP显示为文本的HTML电子邮件

时间:2013-07-22 21:55:00

标签: php html email html-email

我遇到以下代码问题。我发送了HTML消息,但我发送的每个测试都是以文本形式发布的,我需要HTML。

此脚本的目的是允许预先格式化/创建的html电子邮件模板通过CSV文件发送一堆电子邮件地址。对于一小撮电子邮件而言,这对于少数关联公司来说是快速而肮脏的(为此目的而给出的电子邮件地址)。

我已经尝试转义HTML($ message)部分,我尝试使用htmlentities()进行编码,但仍然无法弄明白。

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

一如既往,我们将非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

'\r\n'的所有作业中将"\r\n"更改为$headers。转义序列仅以双引号字符串解释,而不是单引号字符串。