Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- $myMail = "false_email_name@no_email.com";
- //Honeypot example by omer from omerbsh.com
- //your form fields array
- $fields = array(
- 'name' => array('type' => 'text', 'title' => 'enter your name' , 'value' => '' , 'required' => true),
- 'subject' => array('type' => 'text', 'title' => 'enter subject' , 'value' => '' , 'required' => true),
- 'message' => array('type' => 'textarea', 'title' => 'enter your name' , 'value' => 'Your message' , 'required' => true),
- 'send' => array('type' => 'submit', 'title' => 'enter your name' , 'value' => 'Send Form')
- );
- //create form fields html tags
- $form = '<form action="" method="post">';//contain fields
- $form .= ' <input type="text" name="robotest" style="display:none;" />';
- foreach($fields as $key => $field):
- $form .= ' <label for="'.$key.'">'.$field['title'].'</label><br />';
- if ($field['type'] != "textarea") {
- $form .= ' <input type="'.$field['type'].'" name="'.$key.'" value="'.$field['value'].'" /><br />';
- }
- else {//if this is textarea then show in the textarea tags
- $form .= ' <textarea name="'.$key.'">'.$field['value'].'</textarea><br />';
- }
- endforeach;
- $form .= "</form>";
- //if form has been sended
- if(!empty($_POST)):
- $err = false;
- foreach($fields as $key => $field):
- if($_POST[$key] == "" && $field['required'] == true) {//if this field is required
- $form .= "the field ". $key ." is required! , please fill it!<br />";
- $err = true;//there is an error!
- }
- //your form validation here...
- endforeach;
- //Honeypot validation here!
- if($_POST['robotest'] != ""){
- $form .= "sorry , robbots can not send messges to my mail.<br />";
- $err = true;
- }
- if($err == false) { //there is no errors , now im sending the mail.
- mail($myMail, $_POST['subject'], $_POST['message']);
- $form .= "thanks for sending your mail<br />";
- }
- endif;
- ?>
- <html>
- <head>
- <title> Omerbsh.com - Honeypot tester </title>
- </head>
- <body>
- <?php echo $form; ?>
- <br />
- <a href="http://www.omerbsh.com" title="PHP Programmer">PHP Programmer</a>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement