PHP邮件函数中断jquery.post返回数据


PHP mail function interrupting jquery .post return data

我真的不明白这里发生了什么。我有一个jquery脚本,它将表单发布数据发送到注册脚本,在注册脚本中,一封电子邮件被发送给注册用户,用户Id被返回到调用jquery函数,在那里它被转发到另一个脚本进行处理。

问题:如果我省略了mail函数,那么脚本会非常有效,但是,将其引入脚本会阻止变量返回到调用jquery函数。你知道发生了什么事吗?这是Jquery脚本:

<script>
/* attach a submit handler to the form */
$("#purchaseForm").submit(function(event) {
    var intRegex = /^'d+$/;

/* stop form from submitting normally */
event.preventDefault(); 

    $.post("process_signup.php", $("#purchaseForm").serialize(),function(data){
                                                if(intRegex.test(data)){
                    if(data!=0){
                        alert(data);
                    document.getElementById("bag_contents_hidden").value=data;  
                    $.post("process_order.php", $("#bag_contents").serialize(), function(data2){
                    if(data2){
                    window.location.replace("?process=100&success=1");  
                    }else{
                    window.location.replace("?process=100&fail=1"); 
                    }
                });
            }
        }
else{       //Not Important, validation stuff       

}

        });
  });

//

PHP 
                      if($oid){
               if(mail($email,$title,$message,$headers,'O DeliveryMode=b')){
                    echo $oid;
                    unset($_POST['processorder_hidden']);
                    }else{
                    echo 0; 
                          }
                }

由于您期望来自post请求的数据,mail函数生成的任何错误都肯定会产生问题。

以下是解决问题的正确方法

$status = @mail($to, $subject, $content); //suppress the error generated from being passed to the view
//instead handle it later
if($status) {
   //handle success
} else {
  //handle unsuccess
}