[英]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.