显示消息状态在html页面与PHP -联系论坛


Show message status in html page with PHP - Contact forum

我有我的PHP设置它的工作很好,到目前为止,我的联系方式(我是一个'新手'在PHP)。

我使用echo来显示消息的状态(如果它被发送或不发送)。一旦用户单击发送按钮,状态消息将以一个新的URL显示——PHP文件的URL (somesite.com/forum.php)

我的问题是我可以在我的html文件中显示我的状态信息,我的论坛所在的文件(forum. html)基本上而不是点击发送按钮,然后URL更改为forum.php我可以让URL保持相同的(Forum.html),只是可能,但状态文本在那里(html文件)。

下面是我的代码:
<?php
       $email = $_POST['email'];
       $name = $_POST['name'];
       $message = $_POST['message'];
       $from = 'From: Datcroft Website';
       $to = 'myemail@hotmail.co.uk';
       $subject = 'Datcroft Site Message';
       $body = "From: $name'n E-Mail: $email'n Message: $message'n";
       if ($_POST['submit']) {
           if (mail ($to, $subject, $body, $from)) {
           echo '<center><font color="lightgray"><p>Message Sent Successfully!</p> <p>I will get back in touch as soon as possible.</p></font></center>';
           } else {
           echo '<center><font color="lightgray"><p>Ah! Try again, please?</p></font></center>';
           }
       }
    ?>

我的代码的消息状态部分(我想在论坛。html中显示的东西不是一个新的url:

 echo '<center><font color="lightgray"><p>Message Sent Successfully!</p> <p>I will get back in touch as soon as possible.</p></font></center>';
               } else {
               echo '<center><font color="lightgray"><p>Ah! Try again, please?</p></font></center>';

感谢任何可以为我指出正确方向的人!

您应该将forum.html文件更改为forum.php,然后将PHP代码移动到新forum.php文件的顶部,并将表单提交给self:

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >

然后把if放在你想要显示信息的地方

或者你可以用一个flash消息(一个保存在会话中的变量,一旦使用一次就会被删除)从forum.php重定向回来,如果它被设置为

,则显示在html上。