我在使用以下代码时遇到问题。我让它发送 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>
一如既往,任何帮助将不胜感激。