我从一些网站上删除了此代码,以便在我的网站上以各种形式使用。但我今天有一位朋友给我发短信说“嘿,我试图通过你的网站与你联系。”这引起了我脑海中的警报......“你受伤了吗?”所以我进入了重度测试模式,似乎我的表单没有通过电子邮件发送到我的帐户的唯一方法是我从手机提交它们。最糟糕的是,该网站将提交视为表单已发送。没有错误消息。这是代码: `
$email_to = "info@optiprintdesign.com";
$email_subject = "Contact Form Message - Opti Print and Design";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['username']) ||
!isset($_POST['usercompany']) ||
!isset($_POST['email']) ||
!isset($_POST['userphone']) ||
!isset($_POST['usersite']) ||
!isset($_POST['userlocation']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$username = $_POST['username'];
$usercompany = $_POST['usercompany'];
$email_from = $_POST['email'];
$userphone = $_POST['userphone'];
$usersite = $_POST['usersite'];
$userlocation = $_POST['userlocation'];
$comments = $_POST['comments'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$username)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($username)."\n";
$email_message .= "Company: ".clean_string($usercompany)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($userphone)."\n";
$email_message .= "Website: ".clean_string($usersite)."\n";
$email_message .= "Location: ".clean_string($userlocation)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
@mail($email_to, $email_subject, $email_message, $headers);
?>
答案 0 :(得分:0)
PHP支持一个错误控制操作符:at符号(@)。什么时候 预先附加到PHP中的表达式,可能是任何错误消息 该表达式生成的内容将被忽略。