Recently we found that someone has sent out unsolicited emails from our server. This has resulted in the server being blacklisted. I assume this is hackers using forms that have not escaped data correctly, or could it be something else as well?
We have a number of sites with their own 'contact us' type forms. I am going through all the forms and making sure the post data is being escaped. I found one form adding POST data to message without validating it first. I have just added a check before sending the email. Do you think the following will suffice, or is it better practice to escape the email post value before running it through the filter_var?
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$message = $email." says hello";
$headers = "From: me@example.com";
mail('to@example.com', 'Subject', $message, $headers);
}
Should I be checking the transfer logs for header injection attacks/other attacks, if so what would I be looking for?