Ajax Contact Form

Hello, I did a php script for contact form.
I’d like a message comes to my email.
When I uploaded the whole website to a hosting, the contact form does not work.
I have changed default email to my email.
Please share me if you know what I have to do.
Please check the script below. Thanks

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$compagny = $_POST['compagny'];
$message = $_POST['message'];

//Validate first
if(empty($name)||empty($email)||empty($message))
{
echo “Name and email and message are required !”;
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\
”;
$msg .= ” Email: $email \\r\
”;
$msg .= ” Compagny: $compagny \\r\
”;
$msg .= ” Message : “.stripslashes($_POST['message']).”\\r\
\
”;
$msg .= “User information \\r\
”;
$msg .= “User IP : “.$_SERVER["REMOTE_ADDR"].”\\r\
”;
$msg .= “Browser info : “.$_SERVER["HTTP_USER_AGENT"].”\\r\
”;
$msg .= “User come from : “.$_SERVER["SERVER_NAME"];

$recipient = “youremail@gmail.com”;// Change the recipient email adress to your adrees
$sujet = “Sender information”;
$mailheaders = “From: $email\\r\
Reply-To: $email\\r\
Return-Path: $email\\r\
”;
$ok = mail($recipient, $sujet, $msg, $mailheaders);

if(isset($ok)){
header(‘Location: index.html’);
}else if(! isset($ok)){
echo “Name and email are required !”;
header(‘Location: index.html’);
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(‘(\
+)’,
‘(\\r+)’,
‘(\	+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(‘|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>

Hi,

Change this:

$ok = mail($recipient, $sujet, $msg, $mailheaders);

to this:

mail($recipient, $sujet, $msg, $mailheaders);

and see what happens.

This part if completely weird:

      if(isset($ok)){
        header(‘Location: index.html’);
        }else if(! isset($ok)){
        echo “Name and email are required !”;
        header(‘Location: index.html’);
        }

and does not make any sense to me.

Hello greg76,
I’ll do a experiment with your idea. I hope this will help me.
I will let you know what happens later.
Thanks

All your quotes, e.g.

$msg = ” Name : $name \\r\
”; 

look like they were written in WORD or something being slanted.
They should be straight.

$msg = " Name : $name \\r\
";