Hi Deathshadow
My current code for processing a users email address is as follows -
Is there anything missing security wise or anything you would suggest to add?
Also should I also be using the isValidEmail() function you suggest?
PHP Code:
if($_POST['Your_Email_Address'] != "") {
$sender = filter_var($_POST['Your_Email_Address'], FILTER_SANITIZE_EMAIL);
if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Your email address is not valid";
}
} else {
$errors[] = 'Please enter your email address';
}
if(strlen($sender) > 200){
$errors[] = 'Maximum length of 200 characters has been exceeded';
} else {
$sender = spam_scrubber($sender);
$sender = space_remover($sender);
}
function spam_scrubber($value) {
// List of very bad values:
$very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:');
// If any of the very bad strings are in
// the submitted value, return an empty string:
foreach ($very_bad as $v) {
if (stripos($value, $v) !== false) return '';
}
// Replace any newline characters with spaces:
$value = str_replace(array( "\r", "\n", "%0a", "%0d", "\\n", "\\r", "'", "\""), ' ', $value);
// Return the value: return trim($value);
}
// End of spam_scrubber() function.
function space_remover($text) {
return preg_replace('/\s+/', ' ', $text);
}