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

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 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么