<?php
session_start();
error_reporting(E_ALL);
// Clean up the input values
foreach($_POST as $key => $value) {
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
$name = trim(strip_tags(stripslashes($_POST['name'])));
$email = trim(strip_tags(stripslashes($_POST['email'])));
$subject = trim(strip_tags(stripslashes($_POST['subject'])));
$message = trim(strip_tags(stripslashes($_POST['message'])));
$successful = "Message was sent";
$failure = "Message was not sent";
$header = "From: $email\r\n";
$validEmail = filter_var($email, FILTER_VALIDATE_EMAIL);
if (isset($name) && isset($email) && isset($subject) && isset($message)) {
if ($validEmail) {
mail ("myemail@email.com", $subject, $message, $header);
header("Location: emailsent.php?message=$successful");
}
else {
header("Location: emailnotsent.php?message=$failure");
}
}
?>
emailnotsent.php:
<?php
session_start();
echo $failure;
?>
emailsent.php:
<?php
session_start();
echo $successful;
?>
我看到“已发送消息”的URL,但页面本身没有显示任何内容。
答案 0 :(得分:4)
答案 1 :(得分:1)
emailnotsent.php
<?php
session_start();
echo $_GET['message'];
?>
emailsent.php
<?php
session_start();
echo $_GET['message'];
?>