bizza77 Posted January 5, 2011 Share Posted January 5, 2011 Hi, I have a form on my homepage which on submit sends the data to my email. I need to know if it it possible to include in the form a read only field containing the refererid in the URL (for instance, if someone were to have visited my homepage by entering; http://www.mypage.com/?refererid=7777, could I capture that 7777 in one of the form fields so that when the form is submitted I recieve the refererid?) Thanks, any help appreciated... Quote Link to comment Share on other sites More sharing options...
Zurev Posted January 5, 2011 Share Posted January 5, 2011 In the line(s) that you send the data to your email why don't you just include: if (isset($_GET['referrerid'])) { $body .= "Referred from ".(int)$_GET['referrerid']; } $body being the variable representing the body of your email. Quote Link to comment Share on other sites More sharing options...
bizza77 Posted January 5, 2011 Author Share Posted January 5, 2011 In the line(s) that you send the data to your email why don't you just include: if (isset($_GET['referrerid'])) { $body .= "Referred from ".(int)$_GET['referrerid']; } $body being the variable representing the body of your email. hi thanks for your reply but i am very new to php and don't understand how to implement that bit of code into a php email form... any help appreciated Quote Link to comment Share on other sites More sharing options...
Zurev Posted January 5, 2011 Share Posted January 5, 2011 Right, well it's a bit easier to assist you if we have the script you're working with. This forum is to assist in coding, we can't do much without some code! Just copy/paste the script you're working with and we'll take a look at it, make sure to remove any database connection info/private information, etc. Quote Link to comment Share on other sites More sharing options...
bizza77 Posted January 5, 2011 Author Share Posted January 5, 2011 Right, well it's a bit easier to assist you if we have the script you're working with. This forum is to assist in coding, we can't do much without some code! Just copy/paste the script you're working with and we'll take a look at it, make sure to remove any database connection info/private information, etc. <?php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = "me@gmail.COM"; // the email address you wish to receive these mails through $yourWebsite = "test"; // 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 // DO NOT EDIT BELOW HERE $error_msg = null; $result = null; 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; exit("Bots not allowed.</p>"); } if ($_SERVER['REQUEST_METHOD'] == "POST") { 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", "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", "porn", "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"); $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://") !== false || strpos($_POST['comments'], "www.") !== false) $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 foreach ($_POST as $key => $value) $_POST[$key] = trim($value); 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 (!preg_match("/^[A-Za-z](['-A-Za-z\s]*['-A-Za-z])*$/", stripslashes($_POST['name']))) { $error_msg .= "The name field must not contain special characters. \n"; } elseif (!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. \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) . ": " . clean($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)) { if (!empty($thanksPage)) { header("Location: $thanksPage"); exit; } else { $result = 'Your mail was successfully sent.'; } } else { $error_msg = 'Your mail could not be sent this time.'; } } 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]); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>My Email Form</title> <style type="text/css"> p.error, p.success { font-weight: bold; padding: 10px; border: 1px solid; } p.error { background: #ffc0c0; color: #f00; } p.success { background: #b3ff69; color: #4fa000; } </style> </head> <body> <!-- --> <?php if ($error_msg != NULL) { echo '<p class="error">ERROR: '. nl2br($error_msg) . "</p>"; } if ($result != NULL) { echo '<p class="success">'. $result . "</p>"; } ?> <form action="<?php echo basename(__FILE__); ?>" 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="<?php get_data("name"); ?>" /><br /> <label for="email">E-mail: *</label> <input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /><br /> <label for="url">Website URL:</label> <input type="text" name="url" id="url" value="<?php get_data("url"); ?>" /><br /> <label for="location">Location:</label> <input type="text" name="location" id="location" value="<?php get_data("location"); ?>" /><br /> <label for="comments">Comments: *</label> <textarea name="comments" id="comments" rows="5" cols="20"><?php get_data("comments"); ?></textarea><br /> </p> <p> <input type="submit" name="submit" id="submit" value="Send" /> </p> </form> </body> </html> so as you see there my form asks for name, email, website, location & comments, but i need there to be another field which captures the refererid and is read only, so that it cannot be tampered with. so essentially i need a way of implementing 'echo $_GET['refererid'];' into a field in my form. so that when i am sent the email i am away of the referer id. on a side note i dont actually seem to be recieving any email from this script, i have tried it out... cheers. Quote Link to comment Share on other sites More sharing options...
Zurev Posted January 5, 2011 Share Posted January 5, 2011 I would replace the last $message .= line with this: $message .= 'Points: '.$points.'\r\n'; if (isset($_GET['referrerid'])) { $message .= "Referred from ".(int)$_GET['referrerid']; } I don't see why you would need a field in your form for it...please elaborate if you can. Also, you aren't getting any email from the script, that's probably a bit more pressing then it not showing the referrer. Can you show us what error it's giving if any? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.