<?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,但页面本身没有显示任何内容。