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.

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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历