- <?php
- // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!
- $yourEmail = "--"; // the email address you wish to receive these mails through
- $yourWebsite = "The Sports Letter - Achievement submission"; // the name of your website
- $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
- $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4
- $requiredFields = "name,email,tutorgroup,pupilssportactivity,pupilsachievement"; // names of the fields you'd like to be required as a minimum, separate each field with a comma
- // DO NOT EDIT BELOW HERE
- $error_msg = null;
- $result = null;
- $requiredFields = explode(",", $requiredFields);
- function clean($data) {
- $data = trim(stripslashes(strip_tags($data)));
- return $data;
- }
- function isBot() {
- $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");
- foreach ($bots as $bot)
- if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
- return true;
- if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
- return true;
- return false;
- }
- if ($_SERVER['REQUEST_METHOD'] == "POST") {
- if (isBot() !== false)
- $error_msg .= "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];
- // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
- // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
- $points = (int)0;
- $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");
- foreach ($badwords as $word)
- if (
- strpos(strtolower($_POST['message']), $word) !== false ||
- strpos(strtolower($_POST['name']), $word) !== false
- )
- $points += 2;
- if (strpos($_POST['pupilssportachievement'], "http://") !== false || strpos($_POST['pupilssportachievement'], "www.") !== false)
- $points += 2;
- if (isset($_POST['nojs']))
- $points += 1;
- if (preg_match("/(<.*>)/i", $_POST['pupilssportachievement']))
- $points += 2;
- if (strlen($_POST['name']) < 3)
- $points += 1;
- if (strlen($_POST['message']) < 15 || strlen($_POST['pupilssportachievement'] > 1500))
- $points += 2;
- // end score assignments
- foreach($requiredFields as $field) {
- trim($_POST[$field]);
- if (!isset($_POST[$field]) || empty($_POST[$field]))
- $error_msg .= "Please fill in all the required fields and submit again.\r\n";
- }
- if (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
- $error_msg .= "The name field must not contain special characters.\r\n";
- 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'])))
- $error_msg .= "That is not a valid e-mail address.\r\n";
- if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
- $error_msg .= "Invalid website url.\r\n";
- if ($error_msg == NULL && $points <= $maxPoints) {
- $subject = "Automatic Form Email";
- $message = "You received this e-mail message through your website: \n\n";
- foreach ($_POST as $key => $val) {
- $message .= ucwords($key) . ": " . clean($val) . "\r\n";
- }
- $message .= "\r\n";
- $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
- $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
- $message .= 'Points: '.$points;
- if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
- $headers = "From: $yourEmail\n";
- $headers .= "Reply-To: {$_POST['email']}";
- } else {
- $headers = "From: $yourWebsite <$yourEmail>\n";
- $headers .= "Reply-To: {$_POST['email']}";
- }
- if (mail($yourEmail,$subject,$message,$headers)) {
- if (!empty($thanksPage)) {
- header("Location: $thanksPage");
- exit;
- } else {
- $result = 'Your mail was successfully sent.';
- $disable = true;
- }
- } else {
- $error_msg = 'Your mail could not be sent this time. ['.$points.']';
- }
- } else {
- if (empty($error_msg))
- $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
- }
- }
- function get_data($var) {
- if (isset($_POST[$var]))
- echo htmlspecialchars($_POST[$var]);
- }
- ?>
- <?php
- if ($error_msg != NULL) {
- echo '<p class="error">ERROR: '. nl2br($error_msg) . "</p>";
- }
- if ($result != NULL) {
- echo '<p class="success">'. $result . "</p>";
- }
- ?>
- <style type="text/css">
- /*Contact form*/
- label {
- width:12em;
- float:left;
- text-align:right;
- margin-right:1.5em;
- display:block
- }
- .submit input {
- margin-left:4.5em;
- }
- input.text {
- border:1px solid #232a15;
- margin:2px;
- border:1px solid #A8A8A8;
- font-family:Verdana,Arial,Helvetica,sans-serif;
- }
- textarea {
- border: 1px solid #232a15;
- margin: 2px;
- border:1px solid #A8A8A8;
- font-family:Verdana,Arial,Helvetica,sans-serif;
- }
- fieldset {
- border:1px solid #232a15;
- padding: 4px;
- border:1px solid #A8A8A8;
- }
- p.error, p.success {
- font-weight: bold;
- padding: 10px;
- border: 1px solid;
- }
- p.error {
- background: #ffc0c0;
- color: #900;
- }
- p.success {
- background: #b3ff69;
- color: #4fa000;
- }
- </style>
- <form name="sports" action="<?php echo basename(__FILE__); ?>" method="post" onSubmit
- ="javascript:document.sports.reset();" >
- <noscript>
- <p><input type="hidden" name="nojs" id="nojs" /></p>
- </noscript>
- <fieldset>
- <div>
- <label for="name">Your name</label>
- <input type="text" class="text" name="name" id="name" size="30" value="<?php if (isset($_POST['name']) && !empty($_POST['name'])) echo $_POST['name']; ?>" />
- </div>
- <div>
- <label for="pupilsname">Pupils name (if different)</label>
- <input type="text" class="text" name="pupilsname" id="pupilsname" size="30" value="<?php if (isset($_POST['pupilsname']) && !empty($_POST['pupilsname'])) echo $_POST
- ['pupilsname']; ?>" />
- </div>
- <div>
- <label for="tutorgroup">Tutor group</label>
- <input type="text" class="text" name="tutorgroup" id="tutorgroup" size="30" value="<?php if (isset($_POST['tutorgroup']) && !empty($_POST['tutorgroup'])) echo $_POST
- ['tutorgroup']; ?>" />
- </div>
- <div>
- <label for="pupilssportactivity">Pupils sport/activity</label>
- <input type="text" class="text" name="pupilssportactivity" id="pupilssportactivity" size="30" value="<?php if (isset($_POST['pupilssportactivity']) && !empty($_POST
- ['pupilssportactivity'])) echo $_POST['pupilssportactivity']; ?>" />
- </div>
- <div>
- <label for="pupilsachievement">Pupils achievement</label>
- <textarea rows="6" cols="40" name="pupilsachievement" id="pupilsachievement" value="<?php if (isset($_POST['pupilsachievement']) && !empty($_POST['pupilsachievement']))
- echo $_POST['pupilsachievement']; ?>" /></textarea>
- </div>
- <div>
- <label for="email">Your email address</label>
- <input type="text" class="text" name="email" id="email" size="30" value="<?php if (isset($_POST['email']) && !empty($_POST['email']))
- echo $_POST['pupilsachievement']; ?>" />
- </div>
- <div class="submit">
- <input type="submit" name="submit" id="submit" value="Submit" />
- </div>
- </fieldset>
- </form>