无法让 php 输出表格
Can't get php to output a form
我正在尝试使用 php 制作函数形式。最初我制作了一个 "index.html" 文件和另一个名为 send.php 的文件。但它没有用。我还尝试在 send.php 中插入 "echo" 并且成功了!所以我将 index.html 转换为 index.php 并在正文关闭标记之前将 php 代码放入其中,但它没有用!所以我意识到错误在代码中,但我从互联网上复制了这些行,但我不太了解 php。有人能帮我吗?这是代码:
字段的name=""是正确的,我检查了。
<?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;
}
}
?>
前 5 行有语法错误,在 $_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();
除了Jetawe,你还必须在验证语句中使用isset()。
$name = ((!isset($_POST['name']) || empty($_POST['name'])) ? null:$_POST['name']);
我正在尝试使用 php 制作函数形式。最初我制作了一个 "index.html" 文件和另一个名为 send.php 的文件。但它没有用。我还尝试在 send.php 中插入 "echo" 并且成功了!所以我将 index.html 转换为 index.php 并在正文关闭标记之前将 php 代码放入其中,但它没有用!所以我意识到错误在代码中,但我从互联网上复制了这些行,但我不太了解 php。有人能帮我吗?这是代码:
字段的name=""是正确的,我检查了。
<?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;
}
}
?>
前 5 行有语法错误,在 $_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();
除了Jetawe,你还必须在验证语句中使用isset()。
$name = ((!isset($_POST['name']) || empty($_POST['name'])) ? null:$_POST['name']);