Sanitize the user input, but first and foremost: make sure there actually is any user input to sanitize:
$foo = $_POST['bar'];
might issue a notice, if that post variable doesn't exist, that's why it's considered good practice to use isset
:
if (!isset($_POST['email']))
exit('No email address provided');//don't use exit, redirect or something
$email = $_POST['email'];
Next, you sanitize and validate the input. For email addresses, that's easily done:
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
exit('Invalid email address given');//again, use redirect here
But all the other stuff has to be processed to avoid something you are wide open to:
Mail injection attacks
I've reviewed a couple of code snippets, in detail. Instead of copy-pasting my existing answers here, or typing them a second, third or fourth time, I'll just list a couple of links to some of these answers:
Side-notes:
If a script contains nothing but PHP code, then the closing ?>
tag is best omitted. This advice is given everywhere, including the official php.net site. Google as to why (whitespacing, parser tokens, ...)
I have the feeling you're not showing us the full code, because you have an opening and closing {}
around everything, except the first statement.
If this code is the actual code, then please remove those redundant brackets: PHP isn't block-scoped, so they serve no purpouse, other than to confuse anyone else who might ever gaze at your code.
$_REQUEST['name']
and/or$_REQUEST['email']
contained newlines. Also, you may want to consider protecting this form against Cross-Site Request Forgery if you aren't already doing so elsewhere. \$\endgroup\$