Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 6th, 2011  |  syntax: PHP  |  size: 6.77 KB  |  views: 177  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!
  3.  
  4. $yourEmail = "me@email.com"; // the email address you wish to receive these mails through
  5. $yourWebsite = "WEBSITE NAME"; // the name of your website
  6. $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
  7. $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4
  8. $requiredFields = "name,email,message"; // names of the fields you'd like to be required as a minimum, separate each field with a comma
  9.  
  10.  
  11. // DO NOT EDIT BELOW HERE
  12. $error_msg = null;
  13. $result = null;
  14.  
  15. $requiredFields = explode(",", $requiredFields);
  16.  
  17. function clean($data) {
  18.         $data = trim(stripslashes(strip_tags($data)));
  19.         return $data;
  20. }
  21. function isBot() {
  22.         $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz");
  23.  
  24.         foreach ($bots as $bot)
  25.                 if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
  26.                         return true;
  27.  
  28.         if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
  29.                 return true;
  30.        
  31.         return false;
  32. }
  33.  
  34. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  35.         if (isBot() !== false)
  36.                 $error_msg .= "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];
  37.                
  38.         // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
  39.         // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
  40.         $points = (int)0;
  41.        
  42.         $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "fuck", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur", "content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");
  43.  
  44.         foreach ($badwords as $word)
  45.                 if (
  46.                         strpos(strtolower($_POST['message']), $word) !== false ||
  47.                         strpos(strtolower($_POST['name']), $word) !== false
  48.                 )
  49.                         $points += 2;
  50.        
  51.         if (strpos($_POST['message'], "http://") !== false || strpos($_POST['message'], "www.") !== false)
  52.                 $points += 2;
  53.         if (isset($_POST['nojs']))
  54.                 $points += 1;
  55.         if (preg_match("/(<.*>)/i", $_POST['message']))
  56.                 $points += 2;
  57.         if (strlen($_POST['name']) < 3)
  58.                 $points += 1;
  59.         if (strlen($_POST['message']) < 15 || strlen($_POST['message'] > 1500))
  60.                 $points += 2;
  61.         // end score assignments
  62.  
  63.         foreach($requiredFields as $field) {
  64.                 trim($_POST[$field]);
  65.                
  66.                 if (!isset($_POST[$field]) || empty($_POST[$field]))
  67.                         $error_msg .= "Please fill in all the required fields and submit again.\r\n";
  68.         }
  69.  
  70.         if (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
  71.                 $error_msg .= "The name field must not contain special characters.\r\n";
  72.         if (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
  73.                 $error_msg .= "That is not a valid e-mail address.\r\n";
  74.         if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
  75.                 $error_msg .= "Invalid website url.\r\n";
  76.        
  77.         if ($error_msg == NULL && $points <= $maxPoints) {
  78.                 $subject = "Automatic Form Email";
  79.                
  80.                 $message = "You received this e-mail message through your website: \n\n";
  81.                 foreach ($_POST as $key => $val) {
  82.                         $message .= ucwords($key) . ": " . clean($val) . "\r\n";
  83.                 }
  84.                 $message .= "\r\n";
  85.                 $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
  86.                 $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
  87.                 $message .= 'Points: '.$points;
  88.  
  89.                 if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
  90.                         $headers   = "From: $yourEmail\n";
  91.                         $headers  .= "Reply-To: {$_POST['email']}";
  92.                 } else {
  93.                         $headers   = "From: $yourWebsite <$yourEmail>\n";
  94.                         $headers  .= "Reply-To: {$_POST['email']}";
  95.                 }
  96.  
  97.                 if (mail($yourEmail,$subject,$message,$headers)) {
  98.                         if (!empty($thanksPage)) {
  99.                                 header("Location: $thanksPage");
  100.                                 exit;
  101.                         } else {
  102.                                 $result = 'Your mail was successfully sent.';
  103.                                 $disable = true;
  104.                         }
  105.                 } else {
  106.                         $error_msg = 'Your mail could not be sent this time. ['.$points.']';
  107.                 }
  108.         } else {
  109.                 if (empty($error_msg))
  110.                         $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
  111.         }
  112. }
  113. function get_data($var) {
  114.         if (isset($_POST[$var]))
  115.                 echo htmlspecialchars($_POST[$var]);
  116. }
  117. ?>
  118.  
  119. <?php
  120. if ($error_msg != NULL) {
  121.         echo '<p class="error">ERROR: '. nl2br($error_msg) . "</p>";
  122. }
  123. if ($result != NULL) {
  124.         echo '<p class="success">'. $result . "</p>";
  125. }
  126. ?>
  127.  
  128. <style type="text/css">
  129.  
  130. /*Contact form*/
  131. label {
  132. width:4em;
  133. float:left;
  134. text-align:right;
  135. margin-right:1.5em;
  136. display:block
  137. }
  138.  
  139. .submit input {
  140. margin-left:4.5em;
  141. }
  142.  
  143. input.text {
  144. border:1px solid #232a15;
  145. margin:2px;
  146. border:1px solid #A8A8A8;
  147. font-family:Verdana,Arial,Helvetica,sans-serif;
  148. }
  149.  
  150. textarea {
  151. border: 1px solid #232a15;
  152. margin: 2px;
  153. border:1px solid #A8A8A8;
  154. font-family:Verdana,Arial,Helvetica,sans-serif;
  155. }
  156.  
  157. fieldset {
  158. border:1px solid #232a15;
  159. padding: 4px;
  160. border:1px solid #A8A8A8;
  161. }
  162.  
  163. p.error, p.success {
  164.                         font-weight: bold;
  165.                         padding: 10px;
  166.                         border: 1px solid;
  167.                 }
  168.                 p.error {
  169.                         background: #ffc0c0;
  170.                         color: #900;
  171.                 }
  172.                 p.success {
  173.                         background: #b3ff69;
  174.                         color: #4fa000;
  175.                 }
  176. </style>
  177.  
  178. <form action="<?php echo basename(__FILE__); ?>" method="post">
  179. <noscript>
  180.                 <p><input type="hidden" name="nojs" id="nojs" /></p>
  181. </noscript>
  182.      <fieldset>
  183.      <div>
  184.      <label for="name">Name</label>
  185.      <input type="text" class="text" name="name" id="name" size="30" value="" />
  186.     </div>
  187.     <div>
  188.      <label for="email">E-mail</label>
  189.      <input type="text" class="text" name="email" id="email" size="30" value="" />
  190.     </div>
  191.     <div>
  192.      <label for="message">Message</label>
  193.      <textarea rows="6" cols="40" name="message" id="message"></textarea>
  194.     </div>
  195.     <div class="submit">
  196.      <input type="submit" name="submit" id="submit" value="Submit" />
  197.     </div>
  198.     </fieldset>
  199.    </form>
clone this paste RAW Paste Data