I'm trying to make a functional form with php. Initially i made an "index.html" file and another file called send.php. But it did't work. I also tried to insert "echo" in send.php and it worked! So i converted index.html into index.php and i put the php code inside of it before the body closing tag the tag , but it didn't work! So i realized that the error was in the code, but i copied these lines form the internet and i don't know php very well. Can someone help me? This is the code:
The name="" of the fields are correct, I checked.
<?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
";
$msg = "Mail : $mail
";
$msg = "Budjet: $budjet
";
$msg = "Society: $society
";
$msg = "Message : ".stripslashes($_POST['message'])."
";
$msg = "User information
";
$msg = "User IP : ".$_SERVER["REMOTE_ADDR"]."
";
$msg = "Browser info : ".$_SERVER["HTTP_USER_AGENT"]."
";
$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
Reply-To: $email
Return-Path: $email
";
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('(
+)',
'(+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>