douzhi19900102
douzhi19900102
2015-11-11 17:19
浏览 23
已采纳

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

I have a problem with my contact form. When I click the send button it just refreshes the page and doesn't send the mail. I tried so many things but couldn't find a solution. I hope somebody can help me.

Here is the php and contact part:

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

        $body ="From: $name
 E-Mail: $email
 Message:
 $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条回答 默认 最新

  • duanju7199
    duanju7199 2015-11-11 17:49
    已采纳

    The problem is that you have a form tag inside another form tag. Try to change the form tag what have the id contact-form to a div tag.

    点赞 评论

相关推荐