2013-04-24 87 views
0

由于我是PHP新手,因此遇到问题。我写了一个简单的联系表单,但在发送消息(一切正常)后,它将我带到一个空白页面。有什么方法可以回到contact.html页面并显示消息“发送成功”?返回上一页和消息

<?php 
    if(isset($_POST['submit'])) { 
     $to ='[email protected]'; 
     $subject =$_POST['subject']; 
     $headers = 'MIME-Version: 1.0' . "\r\n"; 
     $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 
     $message = " 
       <html> 
        <head> 
         <title>$_POST['subject']</title> 
        </head> 
        <body> 
         <b>Person: </b> ".$_POST['name']." </br> 
         <b>Email: </b>  ".$_POST['email']." </br> 
         <b>Message: </b> ".$_POST['detail']." </br> 
        </body> 
       </html>" ; 
    mail($to, $subject, $message, $headers); 
    } 
?> 

回答

0

,所以你需要将它转换为PHP页面你不能在html页面的查询字符串

<?php 


    header('Location: contact.php?msg=sent successfully'); 
    ?> 

contact.php page 

    <?php 

    if($_GET['msg']) 
    { ?> 
    <p> 
    Message has been sent successfully. 
    thank you. 

    </p> 

<?php } 

?> 

其他解决方案:

做出了新的一页Thankyou.html留言和使用

<?php 


header('Location: Thankyou.html'); 
?> 
+1

由于jquery对我来说依然陌生,所以我决定采用第二种解决方案:)。简单而奔跑!谢谢 – 2013-04-24 11:50:56

0
header("location:contact.php?msg=YOUR_MSG"); 
die(); 
1

可以使用header功能重定向。

header('Location: contact.php?msg=Mail Sent'); 
exit; 

contact.php

if(isset($_GET['msg'])){ 
    echo $_GET['msg']; 
} 
+0

非常感谢! :)它的工作 – 2013-04-24 11:49:36

+0

很高兴帮助你。请不要忘记通过点击左侧的复选标记来接受我的答案。 – Rikesh 2013-04-24 11:54:44

0

在HTML文件中,您不能使用PHP所以首先改变contact.html到contact.php,则:

试试这个:

if (mail($to, $subject, $message, $headers)) { 
header("location:contact.php?msg=sent successfully"); 
} 

In contact.php

if(isset($_GET['msg'])) { 
echo $_GET['msg'] 
}