email() php security?

  • Thread starter Thread starter Johanella
  • Start date Start date
J

Johanella

Guest
Hallo

I have written the following php code that will take information from 3 fields on a web form and then emails it to my email address:

<?php
$email = $_REQUEST['emailfield'] ;
$subject = $_REQUEST['subjectfield'];
$message = $_REQUEST['messagefield'] ;

if (!isset($_REQUEST['emailfield'])) {
header( "Location: http://www.example.com/contactus.html" );
}
elseif (empty($email) || empty($subject) || empty($message)) {
header( "Location: http://www.example.com/error.html" );
}
else {
mail( "[email protected]", $subject,
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
}
?>

However, this code is not very secure and spiders and email farmers can easily use this code to send junk mail to my address.

How can I improve the security of this code?

Thanks
 
Back
Top