BadlyDrawnGirl Posted August 12, 2013 Share Posted August 12, 2013 I am a real novice when it comes to webdesign and thought I properly reproduced the sample code for a basic "contact us" form, but it's not working for some reason. Can someone please, please give me a hand? We are potentially losing business if I can't get this form up and running. Here is the HTML code: <form method="post" action="contact.php" id="contactform"> <div> <p>Please complete as many fields as possible. Thank you!</p> </div> <div> <label>Name <span class="required">*</span></label> <input name="name" type="text" id="name" value="" /> </div> <div> <label>Email <span class="required">*</span></label> <input name="email" type="text" id="email" value="" /> </div> <div> <label>Cell phone</label> <input name="cell" type="text" id="cell" value="" /> </div> <div> <label>Home phone</label> <input name="home" type="text" id="home" value="" /> </div> <div> <label>How can we help you? <span class="required">*</span></label> <textarea name="message" rows="20" cols="50" id="message" ></textarea><br /><br /> </div> <div> <input type="submit" value="Submit" class="button"> <input type="reset" value="Reset" class="button"> </div> </form> And here is the PHP code: <?php if(isset($_POST['submit'])) { $to = "info@eternityglass.com"; $subject = "Question about Eternity Glass"; $name_field = $_POST['name']; $email_field = $_POST['email']; $cell_field = $_POST['cell']; $home_field = $_POST['home']; $message = $_POST['message']; $body = "From: $name_field\n Email: $email_field\n Cell #: $cell_field\n Home: $Home #: $home_field\n Message:\n $message"; echo "Thank you, we will get back to you shortly"; mail($to, $subject, $body); } else { echo "Error!"; } ?> Help! Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/ Share on other sites More sharing options...
fastsol Posted August 12, 2013 Share Posted August 12, 2013 What exactly isn't working? I assume it gives you the Error! instead of sending the email? You need to give the submit button a name="submit" in order for your php to work. I also distribute a ready to go contact form http://amecms.com/article/Easy-to-use-contact-form-with-validation Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444573 Share on other sites More sharing options...
BadlyDrawnGirl Posted August 12, 2013 Author Share Posted August 12, 2013 So if I change the submit code to <input type="submit" value="Submit" class="button" name="submit"> it should work? Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444581 Share on other sites More sharing options...
fastsol Posted August 12, 2013 Share Posted August 12, 2013 Quick glance, yes. Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444582 Share on other sites More sharing options...
BadlyDrawnGirl Posted August 12, 2013 Author Share Posted August 12, 2013 Hmm...well now I'm getting a successful form submit message, but no test emails have hit my inbox yet... Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444588 Share on other sites More sharing options...
fastsol Posted August 12, 2013 Share Posted August 12, 2013 Emails can be a little tricky at times to make work consistently. Start by googling about php email headers, that will help your delivery issue some. Using phpmailer will also help alot cause it's a php class just for emailing things. It provides all the correct headers and stuff to help with delivery. Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444591 Share on other sites More sharing options...
headstress Posted August 12, 2013 Share Posted August 12, 2013 You need to change this <form method="post" action="contact.php" id="contactform"> <div> <p>Please complete as many fields as possible. Thank you!</p> </div> <div> <label>Name <span class="required">*</span></label> <input name="name" type="text" id="name" value="" /> </div> <div> <label>Email <span class="required">*</span></label> <input name="email" type="text" id="email" value="" /> </div> <div> <label>Cell phone</label> <input name="cell" type="text" id="cell" value="" /> </div> <div> <label>Home phone</label> <input name="home" type="text" id="home" value="" /> </div> <div> <label>How can we help you? <span class="required">*</span></label> <textarea name="message" rows="20" cols="50" id="message" ></textarea><br /><br /> </div> <div> <input type="submit" value="Submit" class="button"> <input type="reset" value="Reset" class="button"> </div> </form> to this <form method="post" action="contact.php" id="contactform"> <div> <p>Please complete as many fields as possible. Thank you!</p> </div> <div> <label>Name <span class="required">*</span></label> <input name="name" type="text" value="" /> </div> <div> <label>Email <span class="required">*</span></label> <input name="email" type="text" value="" /> </div> <div> <label>Cell phone</label> <input name="cell" type="text" value="" /> </div> <div> <label>Home phone</label> <input name="home" type="text" value="" /> </div> <div> <label>How can we help you? <span class="required">*</span></label> <textarea name="message" rows="20" cols="50" id="message" ></textarea><br /><br /> </div> <div> <input type="submit" value="Submit" class="button"> <input type="reset" value="Reset" class="button"> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444595 Share on other sites More sharing options...
BadlyDrawnGirl Posted August 12, 2013 Author Share Posted August 12, 2013 Oh man all that header stuff is beyond me...can anyone else help? I honestly do not know anything about coding PHP and am just trying to get a functional form working... Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444597 Share on other sites More sharing options...
headstress Posted August 12, 2013 Share Posted August 12, 2013 Yes see post above remove all the identifiers (id="home") etc, and see if that works Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444598 Share on other sites More sharing options...
BadlyDrawnGirl Posted August 12, 2013 Author Share Posted August 12, 2013 I did that, and don't notice a difference...still haven't received my test emails. Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444599 Share on other sites More sharing options...
fastsol Posted August 12, 2013 Share Posted August 12, 2013 Here are a couple links to help you Yes see post above remove all the identifiers (id="home") etc, and see if that works This has nothing to do with it. The id is only used for the html and css aspects, php doesn't do anything with it. Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444602 Share on other sites More sharing options...
headstress Posted August 12, 2013 Share Posted August 12, 2013 Is the php in a seperate file or is it above the html code on the same page Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444603 Share on other sites More sharing options...
fastsol Posted August 12, 2013 Share Posted August 12, 2013 Is the php in a seperate file or is it above the html code on the same page This also has nothing to do with the issue of not getting the emails. Either the email is getting marked as spam when it leaves the server or because there isn't proper header info the receiving email client is marking it as spam. Have you checked your spam box? One thing you could do to verify the mail function isn't failing is this if(mail($to, $subject, $body)){ echo "Thank you, we will get back to you shortly"; } else { echo 'mail not sent'; } Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444605 Share on other sites More sharing options...
BadlyDrawnGirl Posted August 12, 2013 Author Share Posted August 12, 2013 Have you checked your spam box? Oh my God, why did I not do that before? Yes there they were! I have no idea how to get Gmail to not file these as spam...but at least it's working! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444610 Share on other sites More sharing options...
fastsol Posted August 12, 2013 Share Posted August 12, 2013 Oh the dreaded Gmail, yeah their spam filter system is difficult to deal with. Many many people have issues with them and even if you do all the known tricks it still doesn't work many times. Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444622 Share on other sites More sharing options...
darkfreaks Posted August 13, 2013 Share Posted August 13, 2013 avoiding junk filters all depends on what is in the header. $headers = 'From: YourLogoName info@domain.com' . "\r\n" ; $headers .='Reply-To: '. $to . "\r\n" ; $headers .='X-Mailer: PHP/' . phpversion(); $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; if(mail($to,$subject,$body,$headers)) { echo "mail sent"; } else { echo "mail not sent"; } Quote Link to comment https://forums.phpfreaks.com/topic/281086-basic-contact-form-not-working/#findComment-1444706 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.