would this line of code be sufficient to make the name field secure?
Code:
$sSenderName = filter_input(INPUT_POST, 'senderName' , FILTER_SANITIZE_STRING , FILTER_FLAG_NO_ENCODE_QUOTES);
More complete code:
Code:
// Mail things
$sSenderName = $_POST['senderName'];
$sSenderEmail = $_POST['senderEmail'];
$aEmailMessage = array(
'Name: ' . $sSenderName,
'Email: ' . $sSenderEmail,
);
$semailSubject = "$sSenderName $sSenderEmail scored ". $score . " over ". $scoremax . "."; ;
if(mail('myname@hotmail.com', $semailSubject, implode("\r\n", $aEmailMessage)));
$sSenderName = filter_input(INPUT_POST, 'senderName' , FILTER_SANITIZE_STRING , FILTER_FLAG_NO_ENCODE_QUOTES);
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
if (isset($_REQUEST['senderEmail']))
{//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['senderEmail']);
if ($mailcheck==FALSE)
{
echo "Invalid email address";
echo "<a href='javascript:history.back(1);'><br/>Return to test </a>";
die("");
}
else
{//send email
$email = $_REQUEST['senderEmail'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("someone@example.com", "Subject: $subject",
$message, "From: $sSenderEmail" );
echo "";
}
}
?>
I uploaded the above code and at least saw no errors reported, so I just want to know if it's ok to sanitize and make the name field secure? Thank you.
Bookmarks