我有一個表單發送一個訂單號的電子郵件我想將用戶轉到一個感謝頁面並顯示一條消息「」發送的郵件謝謝你的名字,我們會聯繫您聯繫您的訂單號:」 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