PHP 表单不发送邮件 – 只是重新加载页面

PHP form doesn't send mail – just reloads page

我的联系表有问题。当我点击发送按钮时,它只是刷新页面,并没有发送邮件。我尝试了很多东西,但找不到解决方案。我希望有人能帮助我。

这里是php和联系方式部分:

<?php    
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $subject = $_POST['subject'];

        $body ="From: $name\n E-Mail: $email\n Message:\n $message";


$mail = mail('mymail@gmail.com', $subject, $body);

if ($mail==true)
{
header ("Location: index.php?success=1#contact");
}
else
{
header ("Location: index.php?success=2#contact" );
}

    }
?>

.....

<form id="contact-form">
                <div class="row">
                    <div class="col-md-6">
                <form class="form-horizontal" method="post" role="form" action="index.php">
                        <div class="form-group">
                            <label for="name">Name</label>
                            <input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required="required" />

                        </div>
                        <div class="form-group">
                            <label for="email">
                                Email Address</label>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span>
                                </span>
                                <input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required="required" />           

                            </div>
                        </div>
                        <div class="form-group">
                            <label for="subject">
                                Subject</label>
                            <select id="subject" name="subject" class="form-control" required="required">
                                <option value="na" selected="">Choose One:</option>
                                <option value="service">General Question</option>
                                <option value="suggestions">Suggestions</option>

                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name">
                                Message</label>
                            <textarea id="message" name="message" class="form-control" rows="9" cols="25" required="required" placeholder="CONTACT FORM UNDER CONSTRUCTION! PLEASE USE THE ADRESS AT THE RIGHT/DOWN BELOW."></textarea>

                        </div>
                    </div>
                    <div class="col-md-12">
                        <input type="submit" name="submit" value="SEND" class="btn btn-skin pull-right" id="btnContactUs">
                    </div>
                </div>
                    <div class="form-group">
                        <div class="col-sm-10 col-sm-offset-2">
                            <?php if($_GET['success']  == 1)
{
echo "Thank you. Your message was sent!";
}
elseif ($_GET['success']  == 2) 
{
echo "Sorry, but there were error(s) found with the form you submitted. <br/>Please try again.";
}   
 ?>
                        </div>
                    </div>
                </form>
            </div>
        </div>

</body>

</html>

问题是您在另一个表单标签中有一个表单标签。 尝试将具有 id contact-form 的表单标签更改为 div 标签。