I have the lines of code below on my "contact page" and I'd like to thank the address the visitor by their name when when they're redirected to "thank you page" But the "thank you"page shows up with just "Thanks for contacting us.
<?
$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);
?>
On the Thank you page I have the code below
<?php echo $_POST["name"]; ?> Thanks for contacting us<br />
Thanks
The reason that the name is not showing up is that you are not passing any data to it. You can update your send php file using the codes below:
header('Location:http://www.domain.com/thankyou.php?name='.$name);
thankyou.php
<?php echo $_GET['name']; ?> Thanks for contacting us
$_POST lives only for the current request, so if you change page the array will be gone.
You could use $_SESSIONS instead to store more persistent datas.
Be careful of having session_start()
called at the top of your page when using $_SESSIONS.
$_SESSION['name'] = $_POST['name'];
On your thankyou page:
<?php echo isset($_SESSION['name']) ? $_SESSION['name'] : '';?> Thanks for contacting us<br />
精彩评论