Advertisement
Guest User

Omerbsh.com

a guest
Apr 14th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4.  
  5. $myMail = "false_email_name@no_email.com";
  6. //Honeypot example by omer from omerbsh.com
  7.  
  8. //your form fields array
  9. $fields = array(
  10.     'name'      => array('type' => 'text', 'title' => 'enter your name' , 'value' => '' , 'required' => true),
  11.     'subject'   => array('type' => 'text', 'title' => 'enter subject' , 'value' => '' , 'required' => true),
  12.     'message'   => array('type' => 'textarea', 'title' => 'enter your name' , 'value' => 'Your message' , 'required' => true),
  13.     'send'      => array('type' => 'submit', 'title' => 'enter your name' , 'value' => 'Send Form')
  14.     );
  15.  
  16.  
  17. //create form fields html tags
  18.  
  19. $form = '<form action="" method="post">';//contain fields
  20. $form .= '  <input type="text" name="robotest" style="display:none;" />';
  21.  
  22. foreach($fields as $key => $field):
  23.     $form .= '  <label for="'.$key.'">'.$field['title'].'</label><br />';
  24.    
  25.     if ($field['type'] != "textarea") {
  26.         $form .= '  <input type="'.$field['type'].'" name="'.$key.'"  value="'.$field['value'].'"  /><br />';
  27.     }
  28.     else {//if this is textarea then show in the textarea tags
  29.         $form .= '  <textarea name="'.$key.'">'.$field['value'].'</textarea><br />';
  30.     }
  31. endforeach;
  32.  
  33. $form .= "</form>";
  34.  
  35. //if form has been sended
  36. if(!empty($_POST)):
  37.     $err = false;
  38.    
  39.     foreach($fields as $key => $field):
  40.         if($_POST[$key] == "" && $field['required'] == true) {//if this field is required
  41.             $form .= "the field ". $key ." is required! , please fill it!<br />";
  42.             $err = true;//there is an error!
  43.         }
  44.  
  45.         //your form validation here...
  46.  
  47.     endforeach;
  48.     //Honeypot validation here!
  49.     if($_POST['robotest'] != ""){
  50.         $form .= "sorry , robbots can not send messges to my mail.<br />";
  51.         $err = true;
  52.     }
  53.  
  54.     if($err == false) { //there is no errors , now im sending the mail.
  55.         mail($myMail, $_POST['subject'], $_POST['message']);
  56.         $form .= "thanks for sending your mail<br />";
  57.     }
  58.  
  59. endif;
  60. ?>
  61. <html>
  62.     <head>
  63.         <title> Omerbsh.com - Honeypot tester </title>
  64.     </head>
  65. <body>
  66. <?php  echo $form; ?>
  67. <br />
  68. <a href="http://www.omerbsh.com" title="PHP Programmer">PHP Programmer</a>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement