单击“发送”按钮时,页面未显示文本已成功发送

时间:2019-11-29 07:51:34

标签: php html

所以我正尝试使用带有验证的PHP制作联系表格。因此,当输入字段未填写并且我单击发送按钮时,它会显示错误,提示您填写所有空白,但是当我填写所有内容并单击发送按钮时,它会向我的电子邮件地址发送消息,但不会显示消息已成功发送,仅显示“找不到页面”,这是我的contact.php和send.php代码

 <div class="container">
        <div class="row text-center">

            <div class="col-12 heading">
                <h1>Contact Us</h1>
            </div>
            <div class="col-12">
                <?php 
                    $Msg = "";
                    if(isset($_GET['error'])) {
                        $Msg = "Please Fill in All Blannks";
                        echo '<div class="alert alert-danger">'.$Msg.'</div>';
                    }

                    if(isset($_GET['success'])) {
                        $Msg = "Your Message Has Been Sent";
                        echo '<div class="alert alert-success">'.$Msg.'</div>';
                    }

                ?>

            </div>

        </div>
    </div>



    <div class="container">
                        <div class="row text-center">
                            <div class="col-12">
                                <form class="reportform" action="send.php" method="post">
                                    <input type="text" name="UName" placeholder="Full Name"><br>
                                    <input type="email" name="Email" placeholder="Your e-mail"><br>
                                    <input type="text" name="Subject" placeholder="Subject"><br>
                                    <textarea name="msg" placeholder="Message"></textarea><br>
                                    <h6>By clicking send button, you agree our <a target="_blank" href="../credits/ppolicy.html">Privacy Policy</a></h6>
                                    <button type="submit" name="btn-send" class="btn btn-primary sendbtn">Send</button>
                                </form>
                            </div>
                        </div> 
                    </div>



<?php

if(isset($_POST['btn-send'])){

   $UserName = $_POST['UName'];
   $Email = $_POST['Email'];
   $Subject = $_POST['Subject'];    
   $Msg = $_POST['msg'];

   if(empty($UserName) || empty($Email) || empty($Subject) || empty($Msg)) {

       header('location: contact.php?error'); 

   }

       else {
    $to = "nika.makhatadze17@gmail.com";

    if(mail($to,$Subject,$Msg,$Email)) {

        header("location: index.php?success");
    }
}
}

else {
    header("location: contact.php");
}

?>

2 个答案:

答案 0 :(得分:0)

通过Success,您重定向到index.php?success,但是您在contact.php中定义了成功案例,所以我想说,您只需要将header("location: index.php?success");更改为{{1} }

答案 1 :(得分:0)

嘿,尝试这段代码,我们要对您的代码进行一些更改

在标头位置传递成功味精值

<div class="container">
    <div class="row text-center">

        <div class="col-12 heading">
            <h1>Contact Us</h1>
        </div>
        <div class="col-12">
            <?php 
                $Msg = "";
                if(isset($_GET['error'])) {
                    $Msg = "Please Fill in All Blannks";
                    echo '<div class="alert alert-danger">'.$Msg.'</div>';
                }

                if(isset($_GET['success'])) {
                    $Msg = "Your Message Has Been Sent";
                    echo '<div class="alert alert-success">'.$Msg.'</div>';
                }

            ?>

        </div>

    </div>
</div>

<div class="container">
    <div class="row text-center">
        <div class="col-12">
            <form class="reportform" action="send.php" method="post">
                <input type="text" name="UName" placeholder="Full Name"><br>
                <input type="email" name="Email" placeholder="Your e-mail"><br>
                <input type="text" name="Subject" placeholder="Subject"><br>
                <textarea name="msg" placeholder="Message"></textarea><br>
                <h6>By clicking send button, you agree our <a target="_blank" href="../credits/ppolicy.html">Privacy Policy</a></h6>
                <button type="submit" name="btn-send" class="btn btn-primary sendbtn">Send</button>
            </form>
        </div>
    </div> 
</div>



<?php

if(isset($_POST['btn-send'])){

   $UserName = $_POST['UName'];
   $Email = $_POST['Email'];
   $Subject = $_POST['Subject'];    
   $Msg = $_POST['msg'];

   $successMsg = 1;

   if(empty($UserName) || empty($Email) || empty($Subject) || empty($Msg)) {

       header('location: contact.php?error'); 

   }

       else {
    $to = "nika.makhatadze17@gmail.com";

    if(mail($to,$Subject,$Msg,$Email)) {

       header("location: index.php?success=".$successMsg);
    }
}
}

else {
    header("location: contact.php");
}