0

(我没有意识到我之前已经发布的帖子可以编辑并重新打开。对这个过程感到困惑......)

当我单击发送表单时,电子邮件已正确发送,但随后我被发送到显示数字 0 的 php 页面。我不明白为什么会发生这种情况。这是(大部分)完整的代码:

<form id="contactForm" method="post" action="js/formCheck.php">
    <div class="formCol">
        <label>Email:</label>
        <input type="email" id="formEmail" name="email" autocomplete="off" placeholder="Your email address..." required/>
    </div>
    <div class="formCol midCol">
        <label id="floatMsg">Message (350 chars):</label>
        <textarea id="formMessage" name="message" rows="5" cols="40" maxlength="350" placeholder="What have you got to say?" required></textarea>

    </div>
    <div class="formCol lastCol">
        <input type="submit" class="submit-btn" name="submit" value="Send" />
    </div>
</form>

...脚本

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!--[if lt IE 9]><script src="js/modernizr.custom.js"></script><![endif]-->
<script src="js/jquery.flexslider-min.js"></script>
<script src="js/functions.js"></script>
<script>
    $(document).ready(function() {
        $('#form').ajaxForm(function() {
            alert("Thank you for your comment! I will receive it shortly and get back to you as soon as possible.");
            document.getElementById("form").reset();
        });

    });
</script>

发送电子邮件 (PHP)

if (isset($_POST['submit'])) {
    $email = htmlspecialchars($_POST['email']);
    $comment = htmlspecialchars($_POST['message']);



    /* Sending Email */
    $from_add = "Visitor";
    $to_add = "user@email.com";
    $subject = "The_Message_Subject";
    $message = "
        Message Information
        Email = $email
        Message = $comment";

    $headers = "From: $from_add \r\n";
    $headers .= "Reply-To: $from_add \r\n";
    $headers .= "Return-Path: $from_add \r\n";
    $headers .= "X-Mailer: PHP \r\n";

    mail($to_add, $subject, $message, $headers);
}
4

1 回答 1

4

return false表单重置后添加。表单 idcontactForm也不只是form.

<script>
    $(document).ready(function() {
        $('#contactForm').ajaxForm(function() {
            alert("Thank you for your comment! I will receive it shortly and get back to you as soon as possible.");
            document.getElementById("form").reset();
            return false;
        });
    });
</script> 
于 2013-03-02T02:40:05.977 回答