php提交表单无反应,php表单验证不起作用,允许发送无效提交

我已经编写了一个脚本mail.php来处理表单数据的验证并通过电子邮件发送表单数据。我一直在通过输入已知的无效数据来测试这个脚本,但是这个脚本并不回显错误消息,只是发送数据。

以下是HTML表单:

Fill out the form below to tell me about your problem. Any problems to do with technology, all the solutions. Just tell me what you can, however the more info you give the better.

Tell me a little about whats going on or what you need help with.

Send your message

这里是mail.php:

error_reporting(-1);

ini_set('display_errors', 'On');

set_error_handler("var_dump");

date_default_timezone_set("Pacific/Honolulu");

if (isset($_POST['submit'])) {

$name = $_POST['name'];

$phone = $_POST['phone'];

$email = $_POST['email'];

$date = $_POST['date'];

$time = $_POST['time'];

$message = $_POST['message'];

$subject = "Appointment Booked";

$mailTo = "itguy@johnpuaoi.com";

$email = filter_var($email, FILTER_SANITIZE_EMAIL);

function test_input($data) {

$data = trim($data);

$data = stripslashes($data);

$data = htmlspecialchars($data);

return $data;

}

if (empty($name)) {

$nameErrEmpty = "Your name is required";

} elseif (is_int($name)) {

$nameErr = "That is not a valid name";

} else {

$nameTested = test_input($name);

}

if (empty($phone)) {

$phoneErrEmpty = "Your phone number is required";

} elseif (is_int($name)) {

$phoneTested = test_input($phone);

} else {

$phoneErr = "Phone Number needs to be in this format e.x 1234567890";

}

if (empty($email)) {

$emailErrEmpty = "Your name is required";

} elseif (filter_var($email, FILTER_VALIDATE_EMAIL)) {

$emailErr = "That is not a valid email";

} else {

$emailTested = test_input($name);

}

if (empty($message)) {

$messageErrEmpty ="You must tell me about your problem";

} else {

$messageTested = test_input($message);

}

$dateTested = test_input($date);

$timeTested = test_input($time);

$headers = "From: ".$emailTested;

$txt = "An appointment was booked by ".$nameTested.".\n\n".$dateTested." @".$timeTested.".\n\n".$messageTested;

mail($mailTo, $subject, $txt, $headers);

header("Location: index.php?mailsend");

}

?>

我在堆栈中搜索过类似的问题,但没有找到。我完全不懂php,所以任何帮助都将不胜感激。谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值