douzi8548 2012-05-19 15:16
浏览 14
已采纳

如何停止接收重复邮件?

When a user press submit button I received 7 copies duplicate mail in my administrator email box. How can I receive only one mail. here is my code.

$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 = "mymail@gmail.com";
            $headers = 'MIME-Version: 1.0' . "
";
            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
            $headers .= 'From: Do-Not-Reply@domain.com';
            $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++;
  • 写回答

1条回答 默认 最新

  • dongyaobo9081 2012-05-19 15:28
    关注

    You are sending one email for each coupon code found on the database. You could create a single email message, and send it after the loop:

    $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 = "mymail@gmail.com";
    $headers = 'MIME-Version: 1.0' . "
    ";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    $headers .= 'From: Do-Not-Reply@domain.com';
    $subject = 'New self-serve mail';
    mail($to,$subject,$message,$headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题