2012-05-19 53 views
0

当用户按提交按钮时,我在管理员邮箱中收到7份重复邮件。我怎样才能收到一封邮件。这是我的代码。如何停止接收重复邮件?

$MyCoupon = 0; 
$cResult=mysql_query("select * from codes WHERE status='active'"); 
while($cRow = mysql_fetch_assoc($cResult)){ 
    if($_POST['coupon_used']==$cRow['code'] || $_POST['invoice']=="invoice"){ 

      $coupon = ($_POST['coupon_used']!="" ? $_POST['coupon_used'] : "invoice"); 

      $aRes = mysql_query("SELECT * FROM `adverts` WHERE `ad_id`='".$_POST['ad_id']."'"); 
      $aRow = mysql_fetch_assoc($aRes); 

      $updateQuery = "UPDATE `adverts` SET `message_status`='awaiting approval',`target_impressions`='".$_POST['ad_impressions']."',`recurring`='".$_POST['ad_recurring']."',`coupon_used`='".$coupon."',`POIO`='".$_POST['ad_POIO']."' WHERE `ad_id`='".$_POST['ad_id']."'";   
      $updateResult=mysql_query($updateQuery) or die("Unexpected error: record could not be added.".mysql_error()); 
      include_once("update_ads_from_database.php"); 

      //SEND EMAIL to CC 
       $to = "[email protected]"; 
      $headers = 'MIME-Version: 1.0' . "\r\n"; 
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
      $headers .= 'From: [email protected]'; 
      $subject = 'New self-serve mail'; 
      $message = "The following self-service ad has just been submitted:<br>"; 
      $message .= $aRow['contact_name']."<br>".$aRow['contact_phone']."<br>".$aRow['contact_email']; 
      $message .= "<br><br>Description:".$aRow['description']."<br>Content:".stripslashes($aRow['value'])."<br><br>"; 
      $message .= "Click <a href=\"http://www.domain.com/admin/approve_self_ad.php\">here</a> to approve it."; 
      mail($to,$subject,$message,$headers); 
      $goodCoupon++; 
+0

BOBBY TABLES !!!! –

回答

2

您正在为在数据库中找到的每个优惠券代码发送一封电子邮件。您可以创建一封电子邮件,并在循环后发送:

$MyCoupon = 0; 
// Init empty message body 
$message = ""; 
$cResult=mysql_query("select * from codes WHERE status='active'"); 
while($cRow = mysql_fetch_assoc($cResult)){ 
    if($_POST['coupon_used']==$cRow['code'] || $_POST['invoice']=="invoice"){ 
     $coupon = ($_POST['coupon_used']!="" ? $_POST['coupon_used'] : "invoice"); 
     $aRes = mysql_query("SELECT * FROM `adverts` WHERE `ad_id`='".$_POST['ad_id']."'"); 
     $aRow = mysql_fetch_assoc($aRes); 
     $updateQuery = "UPDATE `adverts` SET `message_status`='awaiting approval',`target_impressions`='".$_POST['ad_impressions']."',`recurring`='".$_POST['ad_recurring']."',`coupon_used`='".$coupon."',`POIO`='".$_POST['ad_POIO']."' WHERE `ad_id`='".$_POST['ad_id']."'";   
     $updateResult=mysql_query($updateQuery) or die("Unexpected error: record could not be added.".mysql_error()); 
     include_once("update_ads_from_database.php"); 

     // Add info on current row to email body 
     $message .= "The following self-service ad has just been submitted:<br>"; 
     $message .= $aRow['contact_name']."<br>".$aRow['contact_phone']."<br>".$aRow['contact_email']; 
     $message .= "<br><br>Description:".$aRow['description']."<br>Content:".stripslashes($aRow['value'])."<br><br>"; 
     $message .= "Click <a href=\"http://www.domain.com/admin/approve_self_ad.php\">here</a> to approve it."; 

     $goodCoupon++; 
    } // end if 
} // end while 

//SEND EMAIL to CC 
$to = "[email protected]"; 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= 'From: [email protected]'; 
$subject = 'New self-serve mail'; 
mail($to,$subject,$message,$headers); 
+0

谢谢你是伟大的,它工作100%:) – Jeniffer