Forum Moderators: coopster
if there is an injection, then it should redirect to the 404 page and die. else, it should send the email and redirect to the success page. currently it only redirects to the 404 page, no email sent. I've tried and retried manipulating the code to work, but I really just don't understand the basic php grammar yet, so I'm very stuck. this website is supposed to go live tomorrow (!) <?php
$myemail = "client@email.com";
function checkFields($values){
$injection = false;
for ($n=0;$n<count($values);$n++){
if (eregi("%0A",$values[$n]) || eregi("%0D",$values[$n]) || eregi("\\r",$values[$n]) || eregi("\\n",$values[$n])){
$injection = true;
}
}
return $injection;
}
$name = $_POST['name'];
$subject = "Message from _____ Site";
$email = $_POST['email'];
$website = $_POST['website'];
$comments = $_POST['comments'];
$result = checkFields(Array($name,$email,$website,$comments));
if ($result==true){
header('Location: ../../404.html');
die;
} else {
$message = "
Your contact form has been submitted by:
Name: $name
E-mail: $email
URL: $website
Comments:
$comments
";
mail($myemail, $subject, $message);
header('Location: ../success.html');
exit;
}
?>
$name = strip_tags($_POST['name']);
$subject = "Message from _____ Site";
$email = strip_tags($_POST['email']);
$website = strip_tags($_POST['website']);
$comments = strip_tags($_POST['comments']);
$message = "Your contact form has been submitted by:\n\r";
$message .= "Name: ".$name."\n\r";
$message .= "E-mail: ".$email."\n\r";
$message .= "URL: ".$website."\n\r";
$message .= "Comments:".$comments."\n\r";
//type plain text or html, delete/comment out as you need :)
$mailheaders = "MIME-version: 1.0\r\n";
$mailheaders .= "content-type: text/plain; charset=UTF-8\r\n";
//for this example I will use plain text
//$mailheaders .= "content-type: text/html; charset=ISO-8859-1\r\n";
mail($myemail, $subject, $message, $mailheaders);
function EmailSanitise($field)
{
//Sanitize email
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//Filter nominated address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
$result = checkFields();//leave parameter field blank
../../404.html construct will come back to haunt you in multiple ways.