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

时间:2015-11-11 17:19:20

标签: php html email submit send

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

这是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>

1 个答案:

答案 0 :(得分:0)

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