繁体   English   中英

单击发送按钮时页面不显示文本已成功发送

[英]page doesn't display that text has been sent successfully when clicked on send button

所以我正在尝试使用带有验证的 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");
}

?>

通过Success ,您重定向到index.php?success但您在contact.php中定义了 Success 案例,所以我会说您只需要更改header("location: index.php?success"); header("location: contact.php?success");

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

在标头位置传递成功消息值

<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");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM