电子邮件发送正常,但它只是停留在空白的mail.php
页面上。没有多余的空格,我在开头添加ob_start
并在标题后面退出。我尝试了各种不同的解决方案,但似乎都没有。我在php上相当新,有没有我错过的东西?
谢谢!
<?php
ob_start();
/* Set e-mail recipient */
$myemail = "xxxxxx@gmail.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$number = check_input($_POST['inputNumber'], "Your Phone Number");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$date = check_input($_POST['inputDate'], "mm-dd-yyyy");
$message = check_input($_POST['inputMessage'], "Your Message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Someone has sent you an appointment request";
$message = "
Someone has sent you a message using your appointment request form:
Name: $name
Number: $number
Email: $email
Date: $date
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: index.php');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>