我有一个表单发送一个订单号的电子邮件我想将用户转到一个感谢页面并显示一条消息“”发送的邮件谢谢你的名字,我们会联系您联系您的订单号:” send_email.php此发送电子邮件和用户转移到谢谢页:首先,我做了一些错误检查,如果没有错误我发送电子邮件php - 标题('Location')的邮件
<?php
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$nameErr = $lastNameErr = $emailErr = $ironingErr = $descriptionErr = $RoomErr = NULL;
$first_name = $last_name = $email = $ironing = $description = $Rooms ="";
if(isset($_POST['submit'])){
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$ironing = $_POST['ironing'];
$Rooms = $_POST['Rooms'];
$Hours = $_POST['Hours'];
$Description = $_POST['description'];
// If email injection is detected, redirect to the error page.
if (isInjected($from)) {
header("Location: $error_page");
}
if (empty($_POST["first_name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["first_name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["description"])) {
$descriptionErr = "Description is required";
} else {
$description = test_input($_POST["description"]);
}
if (empty($_POST["Rooms"])) {
$RoomErr = "Room number is Required";
} else {
$Rooms = test_input($_POST["Rooms"]);
}
if (empty($_POST["Hours"])) {
$HourErr = "Room number is Required";
} else {
$Hours = test_input($_POST["Rooms"]);
}
if ($_POST["Hours"] < 3) {
$RoomErr = "Mininum number of Hours : 3";
} else {
$Rooms = test_input($_POST["Rooms"]);
}
if (empty($_POST["ironing"])) {
$ironingErr = "Ironing is Required";
} else{
$ironing = test_input($_POST["ironing"]);
}
if (isset($nameErr) || isset($lastNameErr) || isset($emailErr) ||
isset($ironingErr) || isset($descriptionErr) || isset($RoomErr)) {
// You have an error
} else {
$today = date("Ymd");
$rand = strtoupper(substr(uniqid(sha1(time())),0,4));
$unique = $today . $rand;
$to = "someemail.com"; // this is your Email address
$subject = "Order Sumbittion: " . $unique;
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: ". $_POST['Rooms'] . "\n\n" ."Number of Hours : ".$_POST['Hours'] . "\n\n" ."Ironing: " . $_POST['ironing'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['description']. "\n\n" . "Number of Rooms: " . $_POST['Rooms']. "\n\n" . "Number of Hours : " . $_POST['Hours'] . "\n\n" ."Ironing: ". $_POST['ironing'] ."\n\n"."Your Odred Number = ". $unique . "\n\n". "Thank you for your Order our Team will be in contact with you shortly."."\n\n". "Check Our facebook page at facebook.com/GlossyCleaningService" ;
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
// sends a copy of the message to the sender
header("Location:thank_you.php?first_name={$first_name}");
exit;
}
}
?>
在我thank_you .php页面我有以下的php脚本
<?php
include ('send_mail.php');
if(isset($_GET['first_name'])) {
echo "Mail Sent. Thank you " . $_GET['first_name'] . ", we will contact you shortly.";
}
?>
我得到的消息我的网页是
“通知:未定义的变量:在/storage/ssd1/717/1954717/public_html/thank_you.php独特的上线126 邮寄。谢谢你,我们会尽快与您联系,您的订单号:“
该网页犯规打印出来的名字或订单号现在看来似乎无法找到它
更新:我改变了我代码凯文·纳尔逊回答我没有得到任何错误或消息只是空白
检查这里的问题:。mysite
尝试在会话中存储订单ID?通过使用标题('Location ...');你重定向用户并且变量丢失 –
在send_mail.php文件中没有'$ first_name'变量,除非你没有向我们展示所有东西。 '头: – TripleDeal
如果你不使用会话和订单ID没有被隐藏,可以通过在GET VAR URL传递它:;' – Kaddath