簡體   English   中英

PHP顯示為文本的HTML電子郵件

[英]HTML E-Mail with PHP Displaying as Text

我遇到以下代碼問題。 我發送了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>

一如往常,任何幫助將不勝感激。

$headers所有作業中將'\\r\\n'更改為"\\r\\n" 轉義序列僅以雙引號字符串解釋,而不是單引號字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM