无法获得联系表格提交

时间:2014-09-13 00:49:42

标签: javascript php jquery html

如果这个工作并测试了它,收到电子邮件没问题。然后就退出了。这可能意味着我改变/删除了一些东西,但我无法弄清楚。

HTML:

<div class="small-12 medium-6 columns" id="form-right">
                <form id="myForm" data-abide="ajax">
                    <div class="contactform">
                    <div class="name-field">
                        <label>Your name <small>required</small>
                        <input id="name" type="text" required pattern="[a-zA-Z]+">
                        <small class="error">Hi I'm Parker. What's your name?</small>
                        </label>

                    </div>
                    <div class="email-field">
                        <label>Email <small>required</small>
                        <input id="email" type="email" required>
                        <small class="error">Oops, you forgot your email.</small>
                        </label>

                    </div>
                    <div class="text-field">
                        <label>Message <small>required</small>
                        </label>
                        <textarea id="message" required></textarea>
                        <small class="error">I see you're the quiet type. How about a short message?</small>
                    </div>
                    <!--<button type="submit">Submit</button>-->
                    <input type="submit" name="sendbutton" id="sendbutton" class="sendbutton button radius" value="Submit" />
                </div>
                </form>
            </div>

JS:

<script>    
    $('#myForm')
    .on('submit', function () {
        var name = $("input#name").val();
        var email = $("input#email").val();
        var message = $("textarea#message").val();

        //Data for response
        var dataString = 'name=' + name +
            '&email=' + email +
            '&message=' + message;

        //Begin Ajax call
        $.ajax({
            type: "POST",
            url:"php/mail.php",
            data: dataString,
            success: function() {
                $('.contactform').html("<div id='thanks'></div>");
                    $('#thanks').html("<h2>Thanks!</h2>")
                    .append("<p>Glad to hear from you "+ name +"! I'll be in touch soon.</p>")
                    .hide()
                    .fadeIn(1500);
            },
            }); //ajax call
            return false;
    });
</script>

PHP:

<?php

$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

$msg = "

Name: $name
Email: $email
Comments: $message
";

$to = "REDACTED";
$subject = "Web Form";
$message = $msg;
$headers = "Web Form";
mail($to,$subject,$message,$headers);

?>

** 编辑:我有一个错误的PHP文件路径。如果我可以,我会删除这个问题。谢谢。 **

1 个答案:

答案 0 :(得分:2)

这很难调试,我实际上尝试发送表单并在开发人员工具中跟踪请求,请注意:

POST http://www.parker-gibson.com/php/mail.php 404 (Not Found) 
jquery.js:25fb.support.cors.a.crossDomain.send jquery.js:25fb.extend.ajax
jquery.js:25(anonymous function) (index):664fb.event.dispatch
jquery.js:25r.handle jquery.js:24

我猜你的路径错了,或者你错过了上传文件......