I am trying to send the content in this form to an email. However, it isn't working and when I submit it gives me an internal error. Here is the code that runs when I am submitting the form.
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['first_name']; // required
$job = $_POST['job']; // required
$company = $_POST['company']; // required
$email = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$psn = $_POST['psn']; // required
$un = $_POST['un']; // required
$weight = $_POST['weight']; // not required
$pieces = $_POST['pieces']; // required
$dgpacked = $_POST['dgpacked']; // required
$address = $_POST['address']; // required
$readytime = $_POST['readytime']; // required
$deliverytype = $_POST['deliverytype']; // required
if(IsInjected($email))
{
echo "Bad email value!";
exit;
}
$email_from = 'c.oswald@live.com';//<== update the email address
$email_subject = "New Quote Request submission";
$email_body = "You have received a new message from the $name with $company.\n".
"Here is the message:\n $message".
$to = "c.oswald@live.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: home.html');
// 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;
}
}
?>
If there is anything more simple, please help me out, I just need something simple enough to understand but not so basic I will have security or injection problems.