0

I have a problem because I'm new to PHP. I wrote a simple contact form, but after sending a message (everything works fine), it takes me to a blank page. Is there any way to go back to the contact.html page and show the message "sent successfully"?

<?php
    if(isset($_POST['submit'])) {
        $to ='contact@centurioagency.com';
        $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);
    }
?>
4

4 回答 4

1

您可以使用标头功能进行重定向。

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

联系人.php

if(isset($_GET['msg'])){
    echo $_GET['msg'];
}
于 2013-04-24T11:40:28.797 回答
0
header("location:contact.php?msg=YOUR_MSG");
die();
于 2013-04-24T11:39:02.573 回答
0

在您的 HTML 文件中,您不能使用 PHP,因此首先将 contact.html 更改为 contact.php ,然后:

尝试这个:

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

在contact.php

if(isset($_GET['msg'])) {
 echo $_GET['msg']
}
于 2013-04-24T11:41:22.877 回答
0

您无法在 html 页面中获取查询字符串,因此您需要将其转换为 php 页面

    <?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');
?>
于 2013-04-24T11:42:28.997 回答