我一直试图制作一个非常简单的联系表格,但我无法弄清楚如何成功地发送"成功发送"消息显示在与我的联系表单相同的页面上(与联系人div在同一窗口中)
这里是php代码(并且不用担心安全问题,而且它只是个人学习的原因)
<?php
$first_name = $_POST ['first_name'];
$last_name = $_POST ['last_name'];
$email = $_POST ['email'];
$message = $_POST ['message'];
$to ="email@gmail.com";
$subject = "new message";
mail ($to, $subject, $message, "From:". $first_name . $last_name);
echo "message";
?>
所以我想要我的#34;消息&#34;出现在我的联系表格上方。有任何想法吗? TY!
答案 0 :(得分:0)
<?php
$first_name = $_POST ['first_name'];
$last_name = $_POST ['last_name'];
$email = $_POST ['email'];
$message = $_POST ['message'];
$to ="email@gmail.com";
$subject = "new message";
if(mail ($to, $subject, $message, "From:". $first_name . $last_name)){
//redirect to the same page sending msg GET variable
header('location:this_page.php?msg=you email has been received.');
}else{
//redirect to the same page sending msg GET variable
header('location:this_page.php?msg=you email has not been received.');
}
//check if msg id set then display
if(isset($_HET['msg'])){
echo $_GET['msg'];
}
?>
答案 1 :(得分:0)
<?php
$first_name = $_POST ['first_name'];
$last_name = $_POST ['last_name'];
$email = $_POST ['email'];
$message = $_POST ['message'];
$to ="email@gmail.com";
$subject = "new message";
mail ($to, $subject, $message, "From:". $first_name . $last_name) or die(header('location:every_page.php?msg=error in send msg');
header('location:this_page.php?msg=you email has been received.');