Fullloop Posted September 24, 2011 Share Posted September 24, 2011 It was suppose to be my day off but here I set in front of the computer trying to figure out some code. I can not get my code to send me the information that is inputted into the fields. The style is what I want but most importantly it has got to work. I'm going to put the PHP code and the HTML code. If you need the CSS code I can post that. I'm not sure if you guys need that though. Hopefully someone out there can help me out. I know it might be a very simple error causing me tons of problems. I just can't figure it out. I'm novice at this stuff. PHP CODE & HTML CODE: <?php if ($_POST["email"]<>'') { $ToEmail = 'Justin@fullloop.net'; $emailSubject = 'contact'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY = "Phone: ".$_POST["phone"]."<br>"; $MESSAGE_BODY .= "Your Email: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "Your Message: ".nl2br($_POST["comment"])."<br>"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> <html> <body> <?php echo $_POST["name"]; ?>,<br /> Thank you for contacting Full Loop Inspections. We take great pride in our services and we are grateful you are considering us to complete your inspection. An inspector will contact you at <?php echo $_POST["phone"]; ?> or email you at <?php echo $_POST["email"]; ?> . </body> </html> <?php } else { ?> <form id="contacts-form" method="post" action="contact.php"> <fieldset> <div class="field"> <label>Your Name:</label> <input type="text" value="" name="name"/> </div> <div class="field"> <label>Your Phone:</label> <input type="text" value="" name="phone"/> </div> <div class="field"> <label>Your E-mail:</label> <input type="text" value="" name="text"/> </div> <div class="field"> <label>Your Message:</label> <textarea cols="1" rows="1"></textarea> </div> <div class="wrapper"><a href="contact-us.html" onClick="document.getElementById('contacts-form').submit()" class="link1"><em><b>SUBMIT</b></em></a></div> </fieldset> </form> <?php }; ?> <!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 profile="http://www.w3.org/2005/10/profile"> <link rel="icon" type="image/gif" href="images/favicon.gif" /> <head> <title>Full Loop Inspections | Columbus Ohio #1 Home Inspector | Home Inspectors | Commercial | Mold | Grove City </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="Certified inspectors performing commercial and home inspections in Columbus, Grove City, Hilliard, Gahanna and surrounding areas" /> <meta name="keywords" content="Columbus home inspectors, Grove City Inspectors, Home Inspections, Home Inspector" /> <meta name="author" content="Full Loop Inspections | Home | Commercial | Mold | Radon | Mold Inspectors - http://www.fullloop.net" /> <link href="style.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="js/cufon-yui.js" type="text/javascript"></script> <script src="js/cufon-replace.js" type="text/javascript"></script> <script src="js/Myriad_Pro_400.font.js" type="text/javascript"></script> <script src="js/Myriad_Pro_600.font.js" type="text/javascript"></script> <script src="js/NewsGoth_BT_400.font.js" type="text/javascript"></script> <script src="js/NewsGoth_BT_700.font.js" type="text/javascript"></script> <script src="js/NewsGoth_Dm_BT_400.font.js" type="text/javascript"></script> <script src="js/script.js" type="text/javascript"></script> <!--[if lt IE 7]> <script type="text/javascript" src="js/ie_png.js"></script> <script type="text/javascript"> ie_png.fix('.png, #header .row-2 ul li a, .extra img, #search-form a, #search-form a em, #login-form .field1 a, #login-form .field1 a em, #login-form .field1 a b'); </script> <link href="ie6.css" rel="stylesheet" type="text/css" /> <![endif]--> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-24965394-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script> </head> <body id="page5"> <div id="main"> <!-- HEADER --> <div id="header"> <div class="row-1"> <div class="fleft"><a href="home.html"><img src="images/logo.png" alt="full-loop-inspections" /></a></div> <div class="fright"> <div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=146395285448812&xfbml=1"></script><fb:like href="http://www.facebook.com/pages/Full-Loop-Inspections/237677882939676" send="true" layout="button_count" width="150" show_faces="true" action="like" font=""></fb:like> <g:plusone size="small"></g:plusone> <ul> <li><a href="home.html"><img src="images/icon1.gif" alt="home-inspections" /></a></li> <li><a href="contact-us.html"><img src="images/icon2-act.gif" alt="contact-a-home-inspector" /></a></li> <li><a href="home-inspectors-service-area.html"><img src="images/icon3.gif" alt="home-inspectors-sitemap" /></a></li> </ul> </div> </div> <div class="row-2"> <div class="left"> <ul> <li><a href="home.html"><span>home</span></a></li> <li><a href="inspection-services.html"><span>inspection services</span></a></li> <li><a href="payments.html"><span>Make Payments</span></a></li> <li><a href="contact-us.html" class="active"><span>contact</span></a></li> <li class="last"><a href="home-inspectors-service-area.html"><span>Service Area</span></a></li> </ul> </div> </div> <div class="row-3"> <div class="inside"> <h2>Columbus Ohio<b>Inspections</b></h2> <p>Full Loop Inspections services Columbus Ohio and surrounding cities. Franklin, Madison, Union, Delaware, Licking, Pickaway and Fairfield counties. Contact us today to set an Inspection appointment. </p> </div> </div> <div class="extra"><img src="images/header-img.png" alt="Columbus-Ohio-Inspectors" /></div> </div> <!-- CONTENT --> <div id="content"><div class="inner_copy">More <a href="http://www.templatemonster.com/">Website Templates</a> at TemplateMonster.com!</div> <div class="box"> <div class="border-bot"> <div class="right-bot-corner"> <div class="left-bot-corner"> <div class="inner"> <div class="box1 alt"> <div class="inner"> <h4><b>Our</b> Contacts</h4> <div class="address"> <p><b>Inspector:</b> Justin Ashley<br /> <b>Telephone:</b>614-256-6505<br /> <b>Address:</b>4690 Helmsbridge Ct<br /> <b>City:</b>Grove City, OH 43123<br /> <b>e-mail:</b><a href="mailto:Justin@Fullloop.net?subject=Online Inspection Referral">Justin@Fullloop.net</a></p> </div> <p class="p0 extra-wrap"><br /> <span class="img-box1"><img src="images/InterNACHI.png" alt="InterNachi-Home-Inspectors" width="81" height="70" /></span><span class="img-box1"><img src="images/Infrared_Certified_Small.png" alt="Thermal-Imaging-home-inspector" width="57" height="70" /></span><span class="img-box1"><img src="images/IAC_Mold_Radon.png" alt="mold-inspector" width="94" height="70" /><img src="images/Columbus-board-of-realtors.jpg" alt="mold-inspector" width="70" height="70" /></span></p> </div> </div> </div> </div> </div> </div> </div> <div class="indent"> <div class="wrapper"> <div class="col-1"> <h3><b>Contact</b> Form</h3> <form id="contacts-form" method="post" action="contact.php"> <fieldset> <div class="field"> <label>Your Name:</label> <input type="text" value="" name="name"/> </div> <div class="field"> <label>Your Phone:</label> <input type="text" value="" name="phone"/> </div> <div class="field"> <label>Your E-mail:</label> <input type="text" value="" name="text"/> </div> <div class="field"> <label>Your Message:</label> <textarea cols="1" rows="1"></textarea> </div> <div class="wrapper"><a href="contact-us.html" onClick="document.getElementById('contacts-form').submit()" class="link1"><em><b>SUBMIT</b></em></a></div> </fieldset> </form> </div> <div class="col-2"> <div class="box2"> <div class="border-top"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="inner"> <h4><b>Property </b>Info</h4> <ul class="news"> <li><a href="full-loop-inspections">Sept 13, 2011</a> <p>When contacting us please provide as much information as you can about the property.</p></li> <li><a href="full-loop-inspections">Sept 13, 2011</a> <p>We will take the time to answer any questions you might have. </p></li> </ul> </div> </div> </div> </div> </div> <div class="box3"> <div class="right-bot-corner"> <div class="left-bot-corner"> <div class="inner"> <center> <p> </p> <p> </p> <p><img src="images/JPicture.jpg" alt="Home-Inspectors-Columbus" /></p> <p> <strong><font color="#FFFFFF">Full Loop Inspections<br /> Certified Home Inspector<br /> Justin Ashley<br /> 4690 Helmsbridge Ct<br /> Grove City, OH 43123<br /> (614)-256-6505</strong><br /><a href="mailto:Justin@Fullloop.net?subject=Inspection"><font color="#000000"> Justin@Fullloop.net</font></a></p> </center> </div> </div> </div> </div> </div> </div> </div> </div> <!-- FOOTER --> <div id="footer"> <div class="footer-nav"> <div class="left"> <ul> <li><a href="home.html">Home</a></li> <li><a href="inspection-services.html">Services</a></li> <li><a href="payments.html">Payments</a></li> <li><a href="contact-us.html">Contact</a></li> <li class="last"><a href="home-inspector-links.html">Links</a></li> </ul> </div> </div> <div class="bottom"><p><a href="http://www.fullloop.net" class="new_window">Full Loop Inspections</a> </p> <p>Servicing <strong>COLUMBUS</strong> - Bexley - Canal Winchester - Dublin - Gahanna - Grandview Heights - Grove City - Hilliard - New Albany - Pickerington - Reynoldsburg - Upper Arlington - Westerville - Whitehall - Worthington and all surrounding cities </p> </div> </div> </div> <script type="text/javascript"> Cufon.now(); </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/ Share on other sites More sharing options...
MasterACE14 Posted September 24, 2011 Share Posted September 24, 2011 this line makes no sense: if ($_POST["email"]<>'') { it should be: if (isset($_POST["email"])) { Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272221 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 you have NO input field named 'email', so $_POST['email'] will never exist. Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272222 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 also... your submit button: <a href="contact-us.html" onClick="document.getElementById('contacts-form').submit()" class="link1"> probably won't work. Just for testing purposes, until you're sure everything else is ok, change that line to something like: <a href="javascript:document.forms['contacts-form'].submit()" class="link1"> or even better, just use a submit button: <input type="submit" value="submit"> Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272223 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 more... 1. you textarea also has no name, should be called 'comment'. 2. $emailSubject is not the same as $EmailSubject , so it will throw an error saying variable does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272225 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 and finally, now that you've sweated a bit over all the errors we just threw at you here's a working version (although all code could be greatly improved) <?php if (isset($_POST["email"])) { $ToEmail = 'Justin@fullloop.net'; $emailSubject = 'contact'; $mailheader = "From: ".$_POST["email"]."\r\n"; //$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "Name: ".$_POST["name"]."<br>"; $MESSAGE_BODY = "Phone: ".$_POST["phone"]."<br>"; $MESSAGE_BODY .= "Your Email: ".$_POST["email"]."<br>"; $MESSAGE_BODY .= "Your Message: ".nl2br($_POST["comment"])."<br>"; mail($ToEmail, $emailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> <html> <body> <?php echo $_POST["name"]; ?>,<br /> Thank you for contacting Full Loop Inspections. We take great pride in our services and we are grateful you are considering us to complete your inspection. An inspector will contact you at <?php echo $_POST["phone"]; ?> or email you at <?php echo $_POST["email"]; ?> . </body> </html> <?php } else { ?> <form id="contacts-form" method="post" action="contact.php"> <fieldset> <div class="field"> <label>Your Name:</label> <input type="text" value="" name="name"/> </div> <div class="field"> <label>Your Phone:</label> <input type="text" value="" name="phone"/> </div> <div class="field"> <label>Your E-mail:</label> <input type="text" value="" name="email"/> </div> <div class="field"> <label>Your Message:</label> <textarea cols="10" rows="5" name="comment"></textarea> </div> <div class="wrapper"><input type="submit" value="submit"></div> </fieldset> </form> <?php }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272227 Share on other sites More sharing options...
Fullloop Posted September 24, 2011 Author Share Posted September 24, 2011 THank you! I can work with that!!!! Damn it... it took me all day and you 5 minutes... LOL Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272230 Share on other sites More sharing options...
Fullloop Posted September 24, 2011 Author Share Posted September 24, 2011 If I wanted it to redirect me to success.html where do I add that? Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272237 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 instead of mail($ToEmail, $emailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); use something like: if(mail($ToEmail, $emailSubject, $MESSAGE_BODY, $mailheader)){ header("Location: success.html"); }else{ header("Location: failure.html"); } Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272239 Share on other sites More sharing options...
Fullloop Posted September 24, 2011 Author Share Posted September 24, 2011 Yes sir that worked like a charm! I really appreciate the help! I should have joined here a long time ago... Just curious how I can add validation to the fields I have? An stop spaming by limiting the number of emails one IP can send in a day? Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272244 Share on other sites More sharing options...
WebStyles Posted September 24, 2011 Share Posted September 24, 2011 1. There are many ways you can validate the fields, for validating a phone number, you can use ctype_digit (check that variable only contains numbers), for a name you can use ctype_alpha (checks that variable only contains letters), strlen (checks the length of a variable), preg_match (allows you to check for specific characters, in case of an email, you know it must have an @ sign, a . and at least 8 characters in length, etc...) 2. best method to track/count submissions based on IP address would be to set up a database with `id`,`ipAddress`,`count` then increment the count field on every submission (if IP already exists) or add a new entry. Quote Link to comment https://forums.phpfreaks.com/topic/247749-contact-form-help-me-been-at-this-for-14-hours/#findComment-1272256 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.