Advertisement
Guest User

Untitled

a guest
Mar 6th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1.   <?php
  2.  
  3.         if(isset($_POST['submit'])) {
  4.  
  5.           error_reporting(E_NOTICE);
  6.  
  7.           function valid_email($str)
  8.  
  9.           {
  10.  
  11.           return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
  12.  
  13.              }
  14.  
  15.           if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
  16.  
  17.           {
  18.  
  19.               $to = preg_replace("([\r\n])", "", $_POST['receiver']);
  20.  
  21.               $from = preg_replace("([\r\n])", "", $_POST['email']);
  22.  
  23.               $subject = "Website contact message from ".$_POST['name'];
  24.  
  25.               $message = $_POST['comment'];
  26.  
  27.              
  28.  
  29.               $match = "/(bcc:|cc:|content\-type:)/i";
  30.  
  31.                 if (preg_match($match, $to) ||
  32.  
  33.                     preg_match($match, $from) ||
  34.  
  35.                     preg_match($match, $message)) {
  36.  
  37.                   die("Header injection detected.");
  38.  
  39.                 }
  40.  
  41.               $headers = "From: ".$from."\r\n";
  42.  
  43.               $headers .= "Reply-to: ".$from."\r\n";
  44.  
  45.              
  46.  
  47.         if(mail($to, $subject, $message, $headers))
  48.  
  49.               {
  50.  
  51.                   echo 1; //SUCCESS
  52.  
  53.               }
  54.  
  55.               else {
  56.  
  57.                   echo 2; //FAILURE - server failure
  58.  
  59.               }
  60.  
  61.           }
  62.  
  63.           else {
  64.  
  65.           echo 3; //FAILURE - not valid email
  66.  
  67.  
  68.  
  69.           }
  70.  
  71.           }else{
  72.  
  73.              die("Direct access not allowed!");
  74.  
  75.            }
  76.  
  77.  
  78.  
  79.       ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement