我的“联系页面”上面有以下代码行,我想感谢访问者的姓名,当他们被重定向到“感谢您的页面”但是“谢谢”页面显示只是“感谢您与我们联系。
<?
$mailto = 'info@siteripe.com'; // insert the email address you want the form sent to
$returnpage = 'thanks.php'; // insert the name of the page/location you want the user to be returned to
$sitename = '[siteripe.com]'; // insert the site name here, it will appear in the subject of your email
$name = $_POST['name'];
$email = $_POST['email'] ;
$subject = $_POST['subject'];
$message = $_POST['message'];
$phone = $_POST['phone'];
if (!$name) {
print("<strong>Error:</strong> Please provide your name.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
if (!$email) {
print("<strong>Error:</strong> Please provide an email address.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
if (!$subject) {
print("<strong>Error:</strong> Please provide a subject.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
if (!$phone) {
print("<strong>Error:</strong> Please provide a Phone number<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
if (!$message) {
print("<strong>Error:</strong> Please provide a Message<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)){
print("<strong>Error:</strong> this email address is not in a valid format.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
$message = "\n$name submitted the following message:\n\n$message\n\nSender's contact details are as follows:\n\nName: $name\nPhone Number: $phone\nEmail Address: $email\n";
mail($mailto, "$subject", $message, "From: $email");
header("Location: " . $returnpage);
?>
在感谢页面上,我有以下代码
<?php echo $_POST["name"]; ?> Thanks for contacting us<br />
谢谢
答案 0 :(得分:1)
名称未显示的原因是您没有向其传递任何数据。您可以使用以下代码更新您的send php文件:
header('Location:http://www.domain.com/thankyou.php?name='.$name);
thankyou.php
<?php echo $_GET['name']; ?> Thanks for contacting us
答案 1 :(得分:0)
$ _ POST仅适用于当前请求,因此如果更改页面,阵列将消失。
您可以使用$ _SESSIONS来存储更多持久数据。
使用$ _SESSIONS时,请注意在页面顶部调用session_start()
。
$_SESSION['name'] = $_POST['name'];
在你的谢谢你页面上:
<?php echo isset($_SESSION['name']) ? $_SESSION['name'] : '';?> Thanks for contacting us<br />