我正在尝试使用php制作一个功能表单。最初我制作了一个“index.html”文件和另一个名为send.php的文件。但它没有用。我也尝试在send.php中插入“echo”,它有效!所以我将index.html转换为index.php,并在我关闭标签之前将php代码放在其中,但它没有用!所以我意识到错误是在代码中,但我从互联网复制这些行,我不知道PHP非常好。有人能帮我吗?这是代码:
字段的名称=“”是正确的,我查了一下。
<?php
$name = ($_POST['name'];
$mail = ($_POST['mail'];
$budjet = ($_POST['budjet'];
$society = ($_POST['society'];
$message = ($_POST['message'];
$error = "Message sending failed";
$errorMessage = "Sorry your message can not be sent.";
//Validate first
if(empty($name)||empty($mail)||empty($budjet)||empty($society)||empty($message))
{
echo "Please fill al the fields";
header('Location: index.html');
}
//validate against any email injection attempts
if(IsInjected($email))
{
echo "Bad email value";
header('Location: index.html');
}
$msg = "Name : $name \r\n";
$msg = "Mail : $mail \r\n";
$msg = "Budjet: $budjet \r\n";
$msg = "Society: $society \r\n";
$msg = "Message : ".stripslashes($_POST['message'])."\r\n\n";
$msg = "User information \r\n";
$msg = "User IP : ".$_SERVER["REMOTE_ADDR"]."\r\n";
$msg = "Browser info : ".$_SERVER["HTTP_USER_AGENT"]."\r\n";
$msg = "User come from : ".$_SERVER["SERVER_NAME"];
$recipient = "myemail@mail.com"; // Change the recipient email adress to your adrees
$sujet = "Mail da Contact di Hindeto";
$mailheaders = "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n";
if (!$error){
$sending = mail($recipient, $sujet, $msg, $mailheaders);
if ($sending) {
// If the message is sent we output a string to use it
echo "Sent";
} else {
// Display Error Message
echo $errorMessage;
}
} else {
echo $error; // Display Error Message
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
答案 0 :(得分:0)
您在(
$_POST
时出现语法错误
$name = $_POST['name'];
$mail = $_POST['mail'];
$budjet = $_POST['budjet'];
$society = $_POST['society'];
$message = $_POST['message'];
之后
header('Location: index.html');
和header('Location: index.html');
打印exit();
header('Location: index.html');
exit();
答案 1 :(得分:0)
除Jetawe外,您还必须在验证声明中使用isset()。
$name = ((!isset($_POST['name']) || empty($_POST['name'])) ? null:$_POST['name']);