【问题标题】:email body appears multiple times电子邮件正文出现多次
【发布时间】:2012-11-16 20:58:58
【问题描述】:

我正在尝试使用 PHP mail() 循环发送一小批电子邮件。发送电子邮件的脚本工作正常。但是,有一个小故障。虽然收件人都只收到一封电子邮件,但列表中的第一个人收到电子邮件正文 ($MESSAGE_BODY) 一次,第二个人收到正文两次,第三人收到 3 次(然后继续)。我一生都无法弄清楚它为什么会这样做。

发送电子邮件的格式是:

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

这是发送邮件的脚本

$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'."\r\n"; 
$mailheader .= 'Reply-To: me@mydomain.com'."\r\n";
$mailheader .= 'MIME-Version: 1.0'."\r\n";
$mailheader .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; 
$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

有什么建议吗??

在此先感谢

【问题讨论】:

    标签: php email


    【解决方案1】:

    在您使用消息正文的第一行,设置它而不是附加它:

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

    (点已被删除)

    【讨论】:

    • 如此简单,就像一个魅力,感谢这么快的反应!
    【解决方案2】:

    只更改有冲突的变量名。

    if ((isset($emailthemnow))&&(($emailthemnow)=="Yes")) {
    $recipient = $thisrecipient[$a];
    $ToEmail = $recipient; 
    $EmailSubject = $subject; 
    $mailheader = 'From: me@mydomain.com'."\r\n"; 
    $mailheader .= 'Reply-To: me@mydomain.com'."\r\n";
    $mailheader .= 'MIME-Version: 1.0'."\r\n";
    $mailheader .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; 
    $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_FINAL=wordwrap($MESSAGE_BODY,70);
    $mailsent=  mail($ToEmail, $EmailSubject, $MESSAGE_BODY_FINAL, $mailheader) or die ("Not Sent");
    if($mailsent){
    //update a table to record date email was sent
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多