唯一的问题是from字段包含电子邮件 来自雅虎(example@yahoo.com)的地址,我看不到 收件箱中的电子邮件和垃圾文件夹。 这是我使用的脚本:
<?php
function spamcheck($field) {
// Sanitize e-mail address
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
// Validate e-mail address
if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
if ('POST' === $_SERVER['REQUEST_METHOD'])
{
// Check if the "from" input field is filled out
if (isset($_POST["from"])) {
// Check if "from" email address is valid
$mailcheck = spamcheck($_POST["from"]);
if ($mailcheck==FALSE) {
echo "Please enter a valid e-mail address";
} else {
$to = "xxxxx@xxxxxx.com";
$from = filter_var($_POST["from"]); // sender
$subject = $_POST["subject"];
$message = $_POST["message"];
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70, "\r\n");
$header='From: '.$from."\r\n";
// send mail
mail($to,$subject,$message,$header);
}
}
}
?>