我在简单的HTML/PHP/CSS网站上有一个联系表单,我想允许人们发送他们的联系信息,即使他们没有提交他们的电子邮件。联系表单 - 输入的电子邮件地址无效! - 允许它通过
但一切我想,当我通过联系表单提交的消息,它要么返回一些错误,或者返回以下错误:“无效的电子邮件地址进入”
这里是我的contactprocess.php
<?php
include("../config.php");
if(!$_POST) exit;
$email = $_POST['Email_Address'];
$error ="";
$errors ="";
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error.="Invalid email address entered!";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('Link','Quantity','Your_Message');
$required = array('Link','Quantity','Your_Message');
$email_subject = "The Message";
$email_content = "new message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if(empty($_POST[$value])) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content)) {
header('Location: http://example.com');
} else {
echo 'ERROR!';
}
}
?>
我敢肯定,这是一个简单的编辑,但我不能弄清楚。
只是匹配电子邮件字段与一些正则表达式来验证电子邮件。 –
Noob问题 - 我该怎么做? :) – Overloard