这让我疯了三天。我无法弄清楚主题和评论为什么不发送。我收到了电子邮件但没有主题和评论。我得到的其他所有东西。
有没有人知道这里发生了什么?此代码适用于其他网站。
<?php
/* Set e-mail recipient */
$myemail = "myemail@outlook.com";
$email_subject = "DO NOT REPLY";
/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$subject = check_input($_POST['subject'], "Write a subject");
$email = check_input($_POST['email']);
$website = check_input($_POST['website']);
$phone = check_input($_POST['phone']);
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("<font color=#cc3333>Please enter a valid <strong>e-mail-address</strong>.\n<br /></font>");
}
/* If URL is not valid set show error message */
if (!preg_match("%^((https?://>/>/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i", $website))
{
show_error("<font color=#cc3333>Please enter a valid <strong>website address</strong>.\n<br /></font>");
}
/* If Name is not valid show error message */
if (!preg_match("/^[A-Za-z\\-\\., \']+$/", $yourname))
{
show_error("<font color=#cc3333>Please enter a valid <strong>name</strong>.\n<br /></font>");
}
/* If Phone is not valid show error message */
if (!preg_match("/^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{3})[\)\.\-\s]*([\d]{3})[\.\-\s]?([\d]{4})$/", $phone))
{
show_error("<font color=#cc3333>Please enter a valid <strong>phone number</strong>.\n<br /></font>");
}
/* If subject is empty show error message */
if($subject = "")
{
show_error("<font color=#cc3333>Please enter a <strong>subject</strong>.\n<br /></font>");
}
/* If message is empty show error message */
if($comments = "")
{
show_error("<font color=#cc3333>Please enter a <strong>message</strong>.\n<br /></font>");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $yourname
Email: $email
Phone: $phone
URL: $website
How did he/she find us? $how_find
Subject: $subject
Comments: $comments
";
// create email headers
$headers = 'From: '.$_POST['email']."\r\n".
'Reply-To: '.$_POST['email']."\r\n" .
'X-Mailer: PHP/' . phpversion();
/* Send the message using mail() function */
mail($myemail, $email_subject, $message, $headers);
/* Redirect visitor to the thank you page */
header('Location: /thankyou.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>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>