Creating a basic secure php mailer I am busy creating a basic php mailer script to post to _self and email to a address.

Is the script secure?

How can I avoid someone clicking on submit the whole time, to spam the mailbox, with minimal extra code

&lt;?php
//Mail header removal
function remove_headers($string) { 
   $headers = array(
   "/to\:/i",
   "/from\:/i",
   "/bcc\:/i",
   "/cc\:/i",
   "/Content\-Transfer\-Encoding\:/i",
   "/Content\-Type\:/i",
   "/Mime\-Version\:/i" 
 ); 
$string = preg_replace($headers, '', $string);
return strip_tags($string);
} 

$to      = "email@tosendto.com";
$subject = "Sent from site";

$uname    = remove_headers($_POST['fname']);
$uemail   = remove_headers($_POST['femail']);
$umessage = remove_headers($_POST['fmessage']);
$umessage = "Name : " . $uname . " Email : " . $uemail . " Message : " . $umessage;

if(isset($_POST['submit']))
{
   mail($to, $subject, $umessage, "From: page@website.com");
}   

?&gt;

&lt;div id="mailer" &gt;
  &lt;h1&gt;Message&lt;/h1&gt;
  &lt;form name="test" action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt;
&lt;p&gt;Your Name:&lt;/p&gt;
&lt;input type="text" size="20" name="fname"&gt;&lt;br&gt;&lt;br&gt;
&lt;p&gt;Your Email:&lt;/p&gt;
&lt;input type="text" size="20" name="femail"&gt;&lt;br&gt;&lt;br&gt;
&lt;p&gt;Your Message:&lt;/p&gt;
&lt;textarea name="fmessage" rows="4" cols="20"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;br&gt;
&lt;input type="submit" name="submit" value="Send Message"&gt;
  &lt;/form&gt;
  &lt;?php if(isset($_POST['submit']))
  {
   echo "&lt;p&gt;Sent. We will be in contact shortly.&lt;/p&gt;";
  } ?&gt;

  &lt;/div&gt;
Your using the email sanitize filter on each field, you need to use FILTER_SANITIZE_STRING for the name and FILTER_SANITIZE_FULL_SPECIAL_CHARS for the message field.

Sanitizing is not the same as validating...

VALIDATE Filters

SANITIZE filters