douliang2935 2013-07-22 21:55
浏览 43
已采纳

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

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' . '
';

$headers .= 'Content-type: text/html; charset=iso-8859-1' . '
';

// Additional headers

$headers .= 'To: <'.$cardCodes1[0].'>' . '
';

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

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.

  • 写回答

1条回答 默认 最新

  • dpt62283 2013-07-22 22:04
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面