0

我有一个 jQuery 审查页面,我将数据提交到 submit.php 页面以通过电子邮件发送数据。截至目前,成功后我将其转到“成功”页面,但我宁愿(如果可能)在您提交 review.php 时,弹出通知让您知道它是否邮寄或回显错误。任何帮助都会很棒。

审查.php

    <script>
        function onSuccess(data, status)
        {
            data = $.trim(data);
            $("#notification").text(data);
        }

        function onError(data, status)
        {
            // handle an error
        }        

        $(document).ready(function() {
            $("#submit").click(function(){

                var formData = $("#callAjaxForm").serialize();

                $.ajax({
                    type: "POST",
                    url: "order.php",
                    cache: false,
                    data: formData,
                    success: onSuccess,
                    error: onError
                });

                return false;
            });
        });
    </script>

<form id="callAjaxForm">
                <ul>
                <?php


                    if (is_array($_REQUEST)) {
                        foreach ($_REQUEST as $key => $val) {

                            // This code should support the checkboxes and multiple selects
                            if (is_array($val)) {
                                foreach ($val as $val2) {
                                    echo "<input type='hidden' name='" . $key . "[]' value='" . $val2 . "' />";
                                }
                            }
                            else {
                                echo "<input type='hidden' name='" . $key . "' value='" . $val . "' />";
                            }
                        }
                    }
                ?>
                </ul>
                <div class="ui-body ui-body-b">
                    <fieldset class="ui-grid-a">
                        <button type="submit" data-theme="a">Submit</button>
                    </fieldset>
                </div>
            </form>

提交.php

 if($from == '') {print "You have not entered an email, please go back and try again";} 
 else { 
 if($name == '') {print "You have not entered a name, please go back and try again";} 
 else { 
 $send = mail($to, $subject, $body, $headers); 
 $send2 = mail($from, $subject2, $autoreply, $body, $additional_headers); 
 $send3 = mail($name2, $subject2, $autoreply2, $additional_headers); 
 $result = 'success';

 if($send) 
 {echo json_encode($result);} 
 else 
 {print "We encountered an error sending your mail, please review your information"; } 
 }
}
4

0 回答 0