为什么我的联系表格在提交后通过电子邮件发送给我?

时间:2014-04-10 03:08:25

标签: php

我是PHP的新手,所以请在这里忍受。

似乎表单已经完成,我没有收到任何错误,但我从未收到过电子邮件。

提前谢谢!!

这是我的HTML

<form class="form-horizontal" role="form" method="POST" id="contact-form" action="contact-form/form.php" style="padding-bottom: 5em;">
                        <div class="form-group">
                            <label class="sr-only" for="name">Name</label>
                            <div class="col-md-12">
                                <input type="text" class="form-control" name="name" id="name" placeholder="Enter Name">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label class="sr-only" for="email">Email</label>
                            <div class="col-md-12">
                                <input type="email" class="form-control" name="email" id="email" placeholder="Enter Email">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label class="sr-only" for="message">Message</label>
                            <div class="col-md-12">
                                <textarea class="form-control" name="message" rows="10"></textarea>
                            </div>
                        </div>
                        <br>
                        <div class="form-actions">
                            <input type="hidden" name="save" value="contact">
                            <button type="submit" class="btn btn-default">Submit</button>
                        </div>
                    </form>

这是我的php

<?php 
// check for form submission - if it doesn't exist then send back to contact form  
if (!isset($_POST["save"]) || $_POST["save"] != "contact") {  
    header("Location: ../index.php"); exit;  
}          
// get the posted data  
$name = $_POST["name"];  
$email_address = $_POST["email"];  
$message = $_POST["message"];
$headers = 'From: '.$email_address."\r\n" .
    'X-Mailer: PHP/' . phpversion();  
    // write the email content  
$email_content = "Name: $name\n";  
$email_content .= "Email Address: $email_address\n";  
$email_content .= "Message:\n\n$message";      
    // send the email  
mail ("myEmail", "Someone Wants a Website!", $email_content, $headers);

$to = $_POST['email'];
$subject = 'Thank you for contacting me!';
$msg = 'I have recieved your correspondence and will get back to you as soon as I can. Best regards, Mike Wilcox Designs';
mail($to, $subject, $msg); 
header("Location: ../index.php"); exit;           
?>

我也在使用jquery验证

<script>
    $(document).ready(function () {

    $('#contact-form').validate({
        rules: {
            name: {
                minlength: 2,
                required: true
            },
            email: {
                required: true,
                email: true
            },
            message: {
                minlength: 2,
                required: true
            }
        },
        highlight: function (element) {
            $(element).closest('.control-group').removeClass('success').addClass('error');
        },
        success: function (element) {
            element.text('OK!').addClass('valid')
                .closest('.control-group').removeClass('error').addClass('success');
        }
    });

});
</script>

0 个答案:

没有答案