dppxp79175 2012-11-16 11:04
浏览 93
已采纳

电子邮件正文多次出现

I'm trying to send a small batch of emails in a loop using PHP mail(). The script to send the emails works fine. There is, however, a slight glitch. Whilst the recipients all receive only one email, the first person on the list receives the email body ($MESSAGE_BODY) once, the second person gets the body twice and the third person gets it 3 times (and on it goes). I cannot for the life of me work out why it's doing it.

The form from which the emails are sent is:

<p>Message Text:
<br />
<textarea name="thebody" id="thebody" cols="65" rows="12"><?php echo $row_email['emailtext'];?></textarea>
<script type="text/javascript">CKEDITOR.replace( 'thebody' );</script>
</p>
<table >
<tr>
<th>Site</th>
<th>Email Address</th>
<th colspan="2">Email Now?</th>
</tr>
<?php  
$b = 0;
$q = 1;
while ($row_selfdo = mysql_fetch_assoc($selfdo)) {  ?>
<tr>
<td><?php echo $row_seldo[‘sitename’];?></td>
<td><input type="text" name="emailto[]" style="font-size:9px;" size="20" value="<?php echo $row_selfdo['eaddress']; ?>"/></td>

<td valign="middle">Yes:<input type="radio" name="emailnow[<?php echo $b;?>]" value="Yes" <?php if (isset($mailed) && ($mailed=="Not Yet")) { echo ""; } else echo "disabled='disabled'"; ?> /></td>

<td>No:<input name="emailnow[<?php echo $b;?>]" type="radio" value="No" checked="checked"  <?php if (isset($mailed) && ($mailed=="Not Yet")) { echo ""; } else echo "disabled='disabled'"; ?>? /></td>

</tr>
<?php $b++; $q++; }  ?>
</table>

And here's the script to send the mail

$numb = count($_POST['emailto']);
$num = $numb -1;
$subject=$_POST['subject'];
$thisrecipient = $_POST['emailto'];
$sendtothemnow = $_POST['emailnow'];

for ($a=0;$a<=$num;$a++) {

$emailthemnow = $sendtothemnow[$a];


if ((isset($emailthemnow))&&(($emailthemnow)=="Yes")) {

$recipient = $thisrecipient[$a];
$ToEmail = $recipient; 
$EmailSubject = $subject; 
$mailheader = 'From: me@mydomain.com'."
"; 
$mailheader .= 'Reply-To: me@mydomain.com'."
";
$mailheader .= 'MIME-Version: 1.0'."
";
$mailheader .= 'Content-type: text/html; charset=iso-8859-1'."
"; 
$MESSAGE_BODY .= '<p>'.$_POST['thebody'].'</p>';
$MESSAGE_BODY .= '<p>Kind Regards</p>';
$MESSAGE_BODY .= '<p>The Environment Team</p>';
$MESSAGE_BODY .= 'email footer bits here ';
$MESSAGE_BODY .='<p style="color:#0C0;">Please consider the environment - do you really need to print this email?';

$MESSAGE_BODY=wordwrap($MESSAGE_BODY,70);

$mailsent=  mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Not Sent");

    if($mailsent){
    //update a table to record date email was sent
    }
}//end email send loop

Any suggestions??

Many thanks in advance

  • 写回答

2条回答 默认 最新

  • dqvy87517 2012-11-16 11:06
    关注

    On your first line where you use the message body, set it instead of appending it:

    $MESSAGE_BODY = '<p>'.$_POST['thebody'].'</p>';
    

    (The dot has been removed)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来