<?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;
?>
emailent.php:
<?php
session_start();
echo $successful;
?>
「メッセージが送信されました」という URL が表示されますが、ページ自体には何も表示されません。