Php 如何在主页上显示联系人表单中的消息
我有PHP联系人表单,我希望发送的消息或失败的消息显示在主页内。。我在submit按钮后面有一个id=“notification”的标记,我希望send.php中的消息显示在它里面 我的代码是:Php 如何在主页上显示联系人表单中的消息,php,Php,我有PHP联系人表单,我希望发送的消息或失败的消息显示在主页内。。我在submit按钮后面有一个id=“notification”的标记,我希望send.php中的消息显示在它里面 我的代码是: <form method="post" action="send.php"> <label>Name</label> <input name="name" placeholder="Type Here">
<form method="post" action="send.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Subject</label>
<input name="subject" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<button id="submit" name="submit" type="submit">Dergo</button>
<h3 id="notification" align="center" style="font-color:green;"></h3>
</form>
名称
电子邮件
主题
消息
杰尔戈
Send.php代码:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = 'From: KontaktFormular';
$to = 'albanianboy2@gmail.com';
$headers = "From:" . $email . "\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if(@mail($to,$subject,$body,$headers))
{
echo "Mesazhi juaj u dërgua me sukses";
}else{
echo "Gabim! Ju lutemi provoni përsëri.";
}
?>
更改这部分代码:
}else{
echo "Gabim! Ju lutemi provoni përsëri.";
}
致:
然后在主页上,您可以有:
<?php
if(isset($_GET['msg']) && $_GET['msg'] = 1)
{
?>
<h3 id="notification" align="center" style="font-color:green;">
Gabim! Ju lutemi provoni përsëri.
</h3>
<?php
}
?>
加宾!朱鲁特米·普罗沃尼·皮尔斯里。
将代码放入PHP文件中。
您的代码:
<?php session_start(); ?>
<form method="post" action="send.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Subject</label>
<input name="subject" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<button id="submit" name="submit" type="submit">Dergo</button>
<h3 id="notification" align="center" style="font-color:green;">
<?php
if(!empty($_SESSION["notification"])){
echo $_SESSION["notification"];
unset($_SESSION["notification"];
}
?>
</h3>
</form>
名称
电子邮件
主题
消息
杰尔戈
信息
$notification = "put your message";
Javascript:
// Appeding notification to Body
$('#notification').html($notification);
在进行php检查的地方执行此操作
将此css置于顶部:
#notification{
display: none;
}
设置你的div
<div id="notification">
javascript客户端代码在哪里?您需要让查询将消息推送到通知id。我会将其更改为div而不是h3。javascript在哪里?这是一种方法,但是让jquery处理消息在浏览器和代码更新方面更好,尽管这个例子非常好。
#notification{
display: none;
}
<div id="notification">