2012-11-16 87 views
1

我試圖發送一個使用PHP郵件()循環中的一小批電子郵件。發送電子郵件的腳本工作正常。但是,有一點小故障。雖然收件人都只收到一封電子郵件,但名單上的第一個人會收到一封電子郵件正文($ MESSAGE_BODY),第二個人收到正文兩次,第三個人收到三封郵件(並繼續)。我不能爲我的生活找出它爲什麼這樣做。電子郵件正文出現多次

的形式從該郵件發送是:

<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: [email protected]'."\r\n"; 
$mailheader .= 'Reply-To: [email protected]'."\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 

任何建議腳本?

提前

回答

3

在您使用郵件正文的第一行非常感謝,設置它,而不是其附加:

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

(該點已被刪除)

+0

這麼簡單,就像一個魅力,感謝這麼快的反應! –

+0

我很高興它幫助:) – Fenton

0

唯一的變化有衝突的變量名稱。

if ((isset($emailthemnow))&&(($emailthemnow)=="Yes")) { 
$recipient = $thisrecipient[$a]; 
$ToEmail = $recipient; 
$EmailSubject = $subject; 
$mailheader = 'From: [email protected]'."\r\n"; 
$mailheader .= 'Reply-To: [email protected]'."\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 
} 
} 
相關問題