indie Posted September 21, 2010 Share Posted September 21, 2010 I would like a pretty simple email contact form to put on my website. I would like it to show the IP of the sender if possible, and make sure they use a valid email. Fields should be name, username (but not required), and comment. I would like the ability to just paste the code into a website page, and I can style it myself. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/213959-need-contact-us-email-script/ Share on other sites More sharing options...
Pikachu2000 Posted September 21, 2010 Share Posted September 21, 2010 You forgot to say how much you're willing to pay someone to write it. Quote Link to comment https://forums.phpfreaks.com/topic/213959-need-contact-us-email-script/#findComment-1113529 Share on other sites More sharing options...
indie Posted September 21, 2010 Author Share Posted September 21, 2010 Good point. I was hoping it was something someone had that they could share or something someone knew of that they could recommend. If that is not an option I understand. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/213959-need-contact-us-email-script/#findComment-1113531 Share on other sites More sharing options...
monkeytooth Posted September 21, 2010 Share Posted September 21, 2010 Here's a very crude, simple version of a contact form, no special fancy looks or anything added.. But some of the security concerns are dealt with.. All you have to do is take a look through and add your email, your subject etc where required its only a couple variables.. Other than that you need to have the attached file to this post, enjoy! Hope it helps. I whipped this up pretty quick from scratch minus the one little email validation class, but had that laying around as I use it in a lot of builds I do. So I may have missed a ; or a quotation mark somewhere in the code doing it as quick as I did, I didn't test it but know as long as theres no missing things to break the code like I mentioned it should work without fail copy and paste. Oh and upload of that one file to the same directory. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <?php include_once('email.validator.php'); function getRealIpAddr(){if(!empty($_SERVER['HTTP_CLIENT_IP'])){$ip=$_SERVER['HTTP_CLIENT_IP'];}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{$ip=$_SERVER['REMOTE_ADDR'];}return $ip;} function cleaner4inputs($theInput){$theOutput = stripslashes($theInput);$theOutput = htmlspecialchars($theOutput, ENT_QUOTES);$theOutput = str_replace("'", "\\'", $theInput); return $theOutput; /*$theOutput = htmlentities($theOutput);*/} $messageDisplay = ""; if((isset($_POST['submitme'])) AND ($_POST['submitme'] == "Submit")){ if(empty($_POST['name']){$errorFound = "yes"; $messageDisplay .= "• Did not provide a Name, whats your name?";}else{$myname = cleaner4inputs($_POST['name']);} if(empty($_POST['uname']){$myuname = "Not Provided";}else{$myuname = cleaner4inputs($_POST['uname']);} if(empty($_GET['email'])){$errorFound = "yes"; $messageDisplay .= "• Email was not provided.<br />";}else{ $em=$_GET['email']; $validator = new EmailAddressValidator; if ($validator->check_email_address($em)){ /*email is in a good format*/ $myemail = $em; }else{ $errorFound = "yes"; $messageDisplay .= "• Email not formated correctly. Example of good: [email protected]<br />"; } } if(empty($_POST['comment']){$errorFound = "yes"; $messageDisplay .= "• Did not provide a comment, what did you want to say?";}else{$mycomment = cleaner4inputs($_POST['comment']);} if($errorFound == "yes"){echo $messageDisplay;}else{ echo "Thank you for sending us a message, we will get back to you soon"; $myipa = getRealIpAddr(); $email_who = 'your email address'; $titlesubject = "your subject tag?"; $message = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>' . $titlesubject . '</title> </head> </head> <body> <strong>Name:</strong> '.$myname.' <strong>Username:</strong> '.$myuname.' <strong>Email Address:</strong> '.$myemail.' <strong>Comment:</strong> '.$mycomment.' <strong>Users IP:</strong> '.$myipa.' </body> </html>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n"; $headers .= 'From: [email protected]' . "\r\n"; $headers .= 'Reply-To: [email protected]' . "\r\n"; $headers .= '1\r\nX-MSMail-Priority: High' . "\r\n"; $headers .= 'X-Mailer: Monkey Tooth Mailer' . "\r\n"; //$headers .= 'To: ' . $to . ' <' . $to2 . '>' . "\r\n"; mail($email_who, $titlesubject, $message, $headers); } }else{/*do nothing assumes form just loaded*/} ?> <body> <form action="$_SERVER['PHP_SELF']" method="post"> <strong>Name:</strong> <input type="text" name="name" id="name" value="" /><br /> <strong>Userame:</strong> <input type="text" name="uname" id="uname" value="" /><br /> <strong>Email:</strong> <input type="text" name="email" id="email" value="" /><br /> <strong>Comment:</strong><br /><textarea name="comment" id="comment"></textarea><br /> <input type="submit" name="submitme" id="submitme" value="Submit" /> </form> </body> </html> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/213959-need-contact-us-email-script/#findComment-1113536 Share on other sites More sharing options...
indie Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks for sharing! Unfortunately I get: Parse error: syntax error, unexpected '{' in ***/contact.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/213959-need-contact-us-email-script/#findComment-1113541 Share on other sites More sharing options...
trq Posted September 21, 2010 Share Posted September 21, 2010 If you want code written for you we have a freelance board. This board is for help with code you have written and are having issues with. Quote Link to comment https://forums.phpfreaks.com/topic/213959-need-contact-us-email-script/#findComment-1113542 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.