rageagainstmachine Posted September 1, 2010 Share Posted September 1, 2010 i have created my form layout, and i think im almost at a stage where im ready to stitch in the php script to send the email. my question is How, what, and where do i get a script, and is it straight forward enough to use? my contact page http://www.lensart.me.uk/contact.html Any help would be appreciatted Thanks RAm, Link to comment Share on other sites More sharing options...
0 Cupcakes Posted September 1, 2010 Share Posted September 1, 2010 You can try out PHP Mail Form that my good friend Jem developed. Features: Meta header and JavaScript injection protection Tags stripped and whitespace trimmed Validity and length checking on name and e-mail fields IP and browser details included in e-mail Valid data displayed when other errors occur Spam word check Common spam bot blocking New in v2: Bayesian style spam filtering Code sample: function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } // 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", "*******", "clit", "######", "cunilingus", "cunillingus", "cunnilingus", "****", "ejaculate", "***", "felatio", "fellatio", "****", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "*******", "*****", "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"); $exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); foreach ($badwords as $word) if (strpos($_POST['comments'], $word) !== false) $points += 2; foreach ($exploits as $exploit) if (strpos($_POST['comments'], $exploit) !== false) $points += 2; Link to comment Share on other sites More sharing options...
0 rageagainstmachine Posted September 1, 2010 Author Share Posted September 1, 2010 you saving my bacon again? :-) so i see there are a few things i need to edit in that text file. i guess removing fields i dont have, and editing ones to match mine? Then what? upload to root of site, and edit the somthing at the send buttong to point to that file? Sorry...never dont this before Cheers G Link to comment Share on other sites More sharing options...
0 Cupcakes Posted September 1, 2010 Share Posted September 1, 2010 Just replace the fields you don't need, with what you need then add more if you need to. You can easily do this, just pay attention to the format of the script itself to see what you need to add/replicated and where. You can split up the form you have into two as right now it's just one main file. The following goes into form.php: <?php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = " "; // the email address you wish to receive these mails through $yourWebsite = " "; // the name of your website $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4 function isBot() { $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot"); $isBot = false; foreach ($bots as $bot) if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) $isBot = true; if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") $isBot = true; return $isBot; } if ($_SERVER['REQUEST_METHOD'] == "POST") { $error_msg = NULL; if (isBot()) exit("Bots not allowed.</p>"); function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } // 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", "*******", "clit", "######", "cunilingus", "cunillingus", "cunnilingus", "****", "ejaculate", "***", "felatio", "fellatio", "****", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "*******", "*****", "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"); $exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); foreach ($badwords as $word) if (strpos($_POST['comments'], $word) !== false) $points += 2; foreach ($exploits as $exploit) if (strpos($_POST['comments'], $exploit) !== false) $points += 2; if (strpos($_POST['comments'], "http://") === true || strpos($_POST['comments'], "www.") === true) $points += 2; if (isset($_POST['nojs'])) $points += 1; if (preg_match("/(<.*>)/i", $_POST['comments'])) $points += 2; if (strlen($_POST['name']) < 3) $points += 1; if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) $points += 2; // end score assignments if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) { $error_msg .= "Name, e-mail and comments are required fields. \n"; } elseif (strlen($_POST['name']) > 15) { $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n"; } elseif (!ereg("^[A-Za-z' -]*$", $_POST['name'])) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($_POST['email']))) { $error_msg .= "That is not a valid e-mail address. \n"; } elseif (!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."; 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) . ": $val \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 \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } else { $headers = "From: $yourWebsite <$yourEmail> \r\n"; $headers .= "Reply-To: {$_POST['email']}"; } if (mail($yourEmail,$subject,$message,$headers)) { echo '<p>Your mail was successfully sent.</p>'; } else { echo '<p>Your mail could not be sent this time.</p>'; } } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } if ($error_msg != NULL) { echo '<p><strong style="color: red;">ERROR:</strong><br />'; echo nl2br($error_msg) . "</p>"; } ?> The following will get put into the page for your contact form (the extension must be .php): <form action="form.php" method="post"> <noscript><p><input type="hidden" name="nojs" id="nojs" /></p></noscript> <p><label for="name">Name:</label> <input type="text" name="name" id="name" value="" /><br /> <label for="email">E-mail:</label> <input type="text" name="email" id="email" value="" /><br /> <label for="comments">Comments:</label> <textarea name="comments" id="comments" rows="5" cols="20"></textarea><br /></p> <p><input type="submit" name="submit" id="submit" value="Send" /></p> </form> Link to comment Share on other sites More sharing options...
Question
rageagainstmachine
i have created my form layout, and i think im almost at a stage where im ready to stitch in the php script to send the email.
my question is How, what, and where do i get a script, and is it straight forward enough to use? my contact page http://www.lensart.me.uk/contact.html
Any help would be appreciatted
Thanks
RAm,
Link to comment
Share on other sites
3 answers to this question
Recommended Posts