silverglade Posted March 13, 2009 Share Posted March 13, 2009 hi, i made a simple contact form on my website and it isn't posting all of the contact information in the email. any help greatly appreciated. thank you. derek here is the html code for the contact <form id="flowers_form" name="flowers_form" method="post" action="flowers_emailer.php"> <div><label for="message">Send us a message</label><textarea name="message" id="message" cols="30" rows="10"></textarea> </div> <div><label for="name">Name</label><input name="name" id="name" type="text"></input></div> <div><label for="phone">Phone</label><input phone="phone" id="phone" type="text"></input></div> <div><label for="email">Email</label><input email="email" id="email" type="text"></input></div> <div>Select Location:<select name="location" id="location"> <option id="location" name="location" value="nj_fortlee">NJ - Fort Lee</option> <option id="location" name="location" value="nj_jerseycity">NJ - Jersey City</option> <option id="location" name="location" value="nj_princeton">NJ - Princeton</option> <option id="location" name="location" value="nj_shorthills">NJ - Short Hills </option> <option id="location" name="location" value="nj_brid">NJ - Bridgewater</option> <option id="location" name="location" value="nj_eastbrunswick">NJ - East Brunswick</option> <option id="location" name="location" value="nj_newark">NJ - Newark</option> <option id="location" name="location" value="nj_iselin">NJ - Iselin</option> <option id="location" name="location" value="nj_lawrenceville">NJ - Lawrenceville</option> <option id="location" name="location" value="nj_mahwah">NJ - Mahwah</option> <option id="location" name="location" value="nj_morriston">NJ - Morristown</option> <option id="location" name="location" value="nj_mtlaurel">NJ - Mt. Laurel</option> <option id="location" name="location" value="nj_parsippany">NJ - Parsippany</option> <option id="location" name="location" value="nj_redbank">NJ - Red Bank</option> <option id="location" name="location" value="nj_roseland">NJ - Roseland</option> <option id="location" name="location" value="nj_saddlebrook">NJ - Saddle Brook</option> <option id="location" name="location" value="nj_piscataway">NJ - Piscataway</option> <option id="location" name="location" value="ny_nyc">NY - New York City</option> <option id="location" name="location" value="ny_rye">NY - Rye</option> <option id="location" name="location" value="ny_tarrytown">NY - Tarrytown</option> <option id="location" name="location" value="ny_whiteplains">NY - White Plains</option> <option id="location" name="location" value="ny_bohemia">NY - Bohemia</option> <option id="location" name="location" value="ny_hauppauqe">NY - Hauppauqe</option> <option id="location" name="location" value="ny_lakesuccess">NY - Lake Success</option> <option id="location" name="location" value="ny_melville">NY - Melville</option> <option id="location" name="location" value="ny_syosset">NY - Syosset</option> <option id="location" name="location" value="ny_uniondale">NY - Uniondale</option> <option id="location" name="location" value="ct_greenwich">CT - Greenwich</option> <option id="location" name="location" value="ct_stamford">CT - Stamford</option> <option id="location" name="location" value="ca_losangeles">CA - Los Angeles</option> <option id="location" name="location" value="ca_sanfrancisco">CA - San Francisco</option> <option id="location" name="location" value="fl_miami">FL - Miami</option> <option id="location" name="location" value="fl_orlando">FL - Orlando</option> <option id="location" name="location" value="fl_fortlauderdale">FL - Fort Lauderdale</option> <option id="location" name="location" value="fl_palmbeach">FL - Palm Beach</option> <option id="location" name="location" value="dc_washington">DC - Washington</option> <option id="location" name="location" value="pa_philadelphia">PA - Philadelphia</option> <option id="location" name="location" value="pa_allentown">PA - Allentown</option> <option id="location" name="location" value="russia_moscow">RUSSIA - Moscow</option> <option id="location" name="location" value="russia_stpetersburg">RUSSIA - St. Petersburg</option> </select></div> <div><input name="submit" id="submit" value="submit" type="submit"></input></div> </form> and here is the PHP code for the form. named flowers_emailer.php <!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> <body> <?php if(isset($_POST['submit'])) { $to = "derekpainter1@hotmail.com"; $subject = "Flower Events Mailer"; $message = $_POST['message']; $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $location = $_POST['location']; $body = "From: $name\n E-Mail: $email \n Message:\n $message \n Location:\n $location \n Phone:\n $phone"; echo "Thank you for contacting Flower Events!"; mail($to, $subject, $body); } else { echo "blarg!"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/ Share on other sites More sharing options...
Maq Posted March 13, 2009 Share Posted March 13, 2009 Insert Quote hi, i made a simple contact form on my website and it isn't posting all of the contact information in the email. any help greatly appreciated. thank you. derek What part isn't showing up? Are you echoing $body to see what's in it? There's also an easier way to dynamically create these variables: Instead of assigning each one: $message = $_POST['message']; $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $location = $_POST['location']; You can loop through the POST array and create your variables: foreach($_POST as $key => $value) { $$key = $value; } Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784105 Share on other sites More sharing options...
silverglade Posted March 13, 2009 Author Share Posted March 13, 2009 thank you for replying maq and for that cool little loop. it worked great. well, the part that doesnt show up in the email is "phone". also, the echo message only puts "your message has been sent to...etc" but doesnt echo the $subject, or $body. here is the new code for the form. with the cool loop added. <!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> <body> <?php if(isset($_POST['submit'])) { $to = "derekpainter1@hotmail.com"; $subject = "Flower Events Mailer"; foreach($_POST as $key => $value) { $$key = $value; } $body = "From: $name\n E-Mail: $email \n Message: $message \n Location: $location \n Phone: $phone"; echo "Your message has been sent to-"; mail($to, $subject, $body); } else { echo "blarg!"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784119 Share on other sites More sharing options...
Maq Posted March 13, 2009 Share Posted March 13, 2009 Hahaha I can't believe I didn't see this.... See the difference? Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784121 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2009 Share Posted March 13, 2009 Unconditionally overwriting program variables from all $_POST variables, would allow a hacker to set other existing program variables. Some prefix should be used to make the created variables unique or use the extract function using the EXTR_PREFIX_ALL parameter. Edit: For example in your existing code, someone could include $_POST['to'] and $_POST['subject'] and replace your $to and $subject strings with what ever they wanted. phone and email should both not work because the form does not have name="..." parameters for those. The following - phone="phone" email="email" should be - name="phone" name="email" Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784125 Share on other sites More sharing options...
silverglade Posted March 13, 2009 Author Share Posted March 13, 2009 i dont know where i have "phone=phone" in my code. does that mean i should not use the $POST loop? also, thank you maq! the phone line shows up now. that was a tiny newbie little bugger!! lol. Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784133 Share on other sites More sharing options...
Maq Posted March 13, 2009 Share Posted March 13, 2009 i dont know where i have "phone=phone" in my code PFMaBiSmAd, pointed out the same thing I did in addition to your identical email field problem. You weren't declaring the names for your input fields (phone & email) so they weren't being added to your POST array in the emailing page. As pointed out: should be: Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784157 Share on other sites More sharing options...
anf.etienne Posted March 13, 2009 Share Posted March 13, 2009 copy and paste this code back to your html <form id="flowers_form" name="flowers_form" method="post" action="flowers_emailer.php"> <div><label for="message">Send us a message</label><textarea name="message" id="message" cols="30" rows="10"></textarea> </div> <div><label for="name">Name</label><input name="name" id="name" type="text"></input></div> <div><label for="phone">Phone</label><input name="phone" id="phone" type="text"></input></div> <div><label for="email">Email</label><input name="email" id="email" type="text"></input></div> <div>Select Location:<select name="location" id="location"> <option id="location" name="location" value="nj_fortlee">NJ - Fort Lee</option> <option id="location" name="location" value="nj_jerseycity">NJ - Jersey City</option> <option id="location" name="location" value="nj_princeton">NJ - Princeton</option> <option id="location" name="location" value="nj_shorthills">NJ - Short Hills </option> <option id="location" name="location" value="nj_brid">NJ - Bridgewater</option> <option id="location" name="location" value="nj_eastbrunswick">NJ - East Brunswick</option> <option id="location" name="location" value="nj_newark">NJ - Newark</option> <option id="location" name="location" value="nj_iselin">NJ - Iselin</option> <option id="location" name="location" value="nj_lawrenceville">NJ - Lawrenceville</option> <option id="location" name="location" value="nj_mahwah">NJ - Mahwah</option> <option id="location" name="location" value="nj_morriston">NJ - Morristown</option> <option id="location" name="location" value="nj_mtlaurel">NJ - Mt. Laurel</option> <option id="location" name="location" value="nj_parsippany">NJ - Parsippany</option> <option id="location" name="location" value="nj_redbank">NJ - Red Bank</option> <option id="location" name="location" value="nj_roseland">NJ - Roseland</option> <option id="location" name="location" value="nj_saddlebrook">NJ - Saddle Brook</option> <option id="location" name="location" value="nj_piscataway">NJ - Piscataway</option> <option id="location" name="location" value="ny_nyc">NY - New York City</option> <option id="location" name="location" value="ny_rye">NY - Rye</option> <option id="location" name="location" value="ny_tarrytown">NY - Tarrytown</option> <option id="location" name="location" value="ny_whiteplains">NY - White Plains</option> <option id="location" name="location" value="ny_bohemia">NY - Bohemia</option> <option id="location" name="location" value="ny_hauppauqe">NY - Hauppauqe</option> <option id="location" name="location" value="ny_lakesuccess">NY - Lake Success</option> <option id="location" name="location" value="ny_melville">NY - Melville</option> <option id="location" name="location" value="ny_syosset">NY - Syosset</option> <option id="location" name="location" value="ny_uniondale">NY - Uniondale</option> <option id="location" name="location" value="ct_greenwich">CT - Greenwich</option> <option id="location" name="location" value="ct_stamford">CT - Stamford</option> <option id="location" name="location" value="ca_losangeles">CA - Los Angeles</option> <option id="location" name="location" value="ca_sanfrancisco">CA - San Francisco</option> <option id="location" name="location" value="fl_miami">FL - Miami</option> <option id="location" name="location" value="fl_orlando">FL - Orlando</option> <option id="location" name="location" value="fl_fortlauderdale">FL - Fort Lauderdale</option> <option id="location" name="location" value="fl_palmbeach">FL - Palm Beach</option> <option id="location" name="location" value="dc_washington">DC - Washington</option> <option id="location" name="location" value="pa_philadelphia">PA - Philadelphia</option> <option id="location" name="location" value="pa_allentown">PA - Allentown</option> <option id="location" name="location" value="russia_moscow">RUSSIA - Moscow</option> <option id="location" name="location" value="russia_stpetersburg">RUSSIA - St. Petersburg</option> </select></div> <div><input name="submit" id="submit" value="submit" type="submit"></input></div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784158 Share on other sites More sharing options...
silverglade Posted March 13, 2009 Author Share Posted March 13, 2009 awesome thank you everyone! last thing is i guess, does anyone know why my mail($to, $subject, $body); doesnt echo back to the screen? it just goes to the $to variable and stops. Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784169 Share on other sites More sharing options...
anf.etienne Posted March 13, 2009 Share Posted March 13, 2009 i dont know but here is a contact form that i built a while ago and have been using this style for many things. maybe you could get an idea of this <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><title>Submitting Details.....</title> <script language="JavaScript"> <!-- window.location="http://www.yourdomainname.com/"; //--> </SCRIPT> <?php srand(time()); $random = (rand()%10000000); $leadTitle=$_POST['leadTitle']; $leadName=$_POST['leadName']; $leadDayNum=$_POST['leadDayNum']; $leadEvngNum=$_POST['leadEvngNum']; $preferredContact=$_POST['preferredContact']; $leadEmail=$_POST['leadEmail']; $houseNo=$_POST['houseNo']; $leadStreet=$_POST['leadStreet']; $leadTown=$_POST['leadTown']; $leadCounty=$_POST['leadCounty']; $leadPostcode=$_POST['leadPostcode']; $propertyType=$_POST['propertyType']; $noBedrooms=$_POST['noBedrooms']; $sellBy=$_POST['sellBy']; $sellingReason=$_POST['sellingReason']; $IsAgent=$_POST['IsAgent']; $propertyCondition=$_POST['propertyCondition']; $approxValue=$_POST['approxValue']; $additionalInfo=$_POST['additionalInfo']; if($leadTitle){ } else{ $error.="Please, go back and select a title<br>\n"; } if($leadName){ } else{ $error.="Please, go back and enter your name<br>\n"; } if($leadDayNum){ } else{ $error.="Please, go back and enter your daytime contact number<br>\n"; } if($leadEvngNum){ } else{ $error.="Please, go back and enter your evening contact number<br>\n"; } if($preferredContact){ } else{ $error.="Please, go back and enter a preferred contact number<br>\n"; } if($leadEmail){ } else{ $error.="Please, go back and enter your email address<br>\n"; } if($houseNo){ } else{ $error.="Please, go back and enter your house number or name<br>\n"; } if($leadStreet){ } else{ $error.="Please, go back and enter your street name<br>\n"; } if($leadTown){ } else{ $error.="Please, go back and enter your town name<br>\n"; } if($leadCounty){ } else{ $error.="Please, go back and enter your county<br>\n"; } if($leadPostcode){ } else{ $error.="Please, go back and enter your postcode<br>\n"; } if($propertyType){ } else{ $error.="Please, go back and enter the property type<br>\n"; } if($noBedrooms){ } else{ $error.="Please, go back and enter the number of bedrooms<br>\n"; } if($sellBy){ } else{ $error.="Please, go back and enter when you want to sell by<br>\n"; } if($sellingReason){ } else{ $error.="Please, go back and enter your reason for selling<br>\n"; } if($IsAgent){ } else{ $error.="Please, go back and enter the estate agent details<br>\n"; } if($propertyCondition){ } else{ $error.="Please, go back and enter the condition of the property<br>\n"; } if($approxValue){ } else{ $error.="Please, go back and enter the approximate value of the property<br>\n"; } if($additionalInfo){ } else{ $error.="Please, go back and enter the approximate value of the property<br>\n"; } if($error==""){ echo ""; $mailContent="--------LEAD DETAILS--------\n\n" ."Lead Number #".$random."\n" ."Lead Title: ".$leadTitle."\n" ."Lead Name: ".$leadName."\n" ."Lead Daytime Contact No: ".$leadDayNum."\n" ."Lead Evening Contact No: ".$leadEvngNum."\n" ."Lead Preferred Contact No: ".$preferredContact."\n" ."Lead Email: ".$leadEmail."\n\n--------PROPERTY DETAILS--------\n\n" ."Lead House Name/No: ".$houseNo."\n" ."Lead Street Name: ".$leadStreet."\n" ."Lead Town: ".$leadTown."\n" ."Lead County: ".$leadCounty."\n" ."Lead Postcode: ".$leadPostcode."\n" ."Property Type: ".$propertyType."\n" ."No Bedrooms: ".$noBedrooms."\n" ."Sell By: ".$sellBy."\n" ."Reason For Selling: ".$sellingReason."\n" ."Estate Agent Details: ".$IsAgent."\n" ."Condition Of Property: ".$propertyCondition."\n" ."Approximate Value: ".$approxValue."\n\n--------ADDITIONAL INFORMATION--------\n\n" ."Additional Information: ".$additionalInfo."\n"; $toAddress="user@emailaddresshere.com"; $subjectFrom="Receipt: Reciept subject"; $recipientSubject="Lead Number #".$random." created - Report 1"; $receiptMessage="Thank you ".$leadName." for requesting report 1 from www.yourdomainname.com\n\n\nThis is your reciept and the details you submitted:\n\n" ."--------YOUR DETAILS--------\n\n" ."Reference Number #".$random."\n" ."Title: ".$leadTitle."\n" ."Name: ".$leadName."\n" ."Daytime Contact No: ".$leadDayNum."\n" ."Evening Contact No: ".$leadEvngNum."\n" ."Preferred Contact No: ".$preferredContact."\n" ."Email: ".$leadEmail."\n\n--------PROPERTY DETAILS--------\n\n" ."House Name/No: ".$houseNo."\n" ."Street Name: ".$leadStreet."\n" ."Town: ".$leadTown."\n" ."County: ".$leadCounty."\n" ."Postcode: ".$leadPostcode."\n" ."Property Type: ".$propertyType."\n" ."No Bedrooms: ".$noBedrooms."\n" ."Sell By: ".$sellBy."\n" ."Reason For Selling: ".$sellingReason."\n" ."Estate Agent Details: ".$IsAgent."\n" ."Condition Of Property: ".$propertyCondition."\n" ."Approximate Value: ".$approxValue."\n\n--------ADDITIONAL INFORMATION--------\n\n" ."Additional Information: ".$additionalInfo."\n"; mail($leadEmail, $subjectFrom, $receiptMessage,"From:$toAddress"); mail($toAddress,$recipientSubject,$mailContent,"From:$leadEmail"); // OPEN CONNECTION ---> $connection=mysql_connect("-","-", "-") or die("Unable to connect!"); mysql_select_db("-") or die("Unable to select database!"); // EXECUTE QUERY ---> $query="INSERT INTO generalContact ( leadTitle, leadName, leadDayNum, leadEvngNum, preferredContact, leadEmail, houseNo, leadStreet, leadTown, leadCounty, leadPostcode, propertyType, noBedrooms, sellBy, sellingReason, IsAgent, propertyCondition, approxValue, additionalInfo) VALUES( '".$leadTitle."', '".$leadName."', '".$leadDayNum."', '".$leadEvngNum."', '".$preferredContact."', '".$leadEmail."', '".$houseNo."', '".$leadStreet."', '".$leadTown."', '".$leadCounty."', '".$leadPostcode."', '".$propertyType."', '".$noBedrooms."', '".$sellBy."', '".$sellingReason."', '".$IsAgent."', '".$propertyCondition."', '".$approxValue."', '".$additionalInfo."')"; //////-----> $result=mysql_query($query) or die("Error in query:".mysql_error()); //if ($result) //echo mysql_affected_rows()." row inserted into the database effectively."; // CLOSE CONNECTION ---> mysql_close($connection); /////////////////////////////////////////////////////////////////////////////////// } else{ print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - <br>\n"; print "$error<br>\n"; print "<br>\n"; print "<br>\n"; print "Please use your \"Back\" button to return to the form to correct the omissions. Thank you.<br>\n"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784179 Share on other sites More sharing options...
Maq Posted March 13, 2009 Share Posted March 13, 2009 That's really long code for a contact form, you could write a couple for loops to minimize that script 100 lines. awesome thank you everyone! last thing is i guess, does anyone know why my mail($to, $subject, $body); doesnt echo back to the screen? it just goes to the $to variable and stops. You are trying to echo mail()? It only returns a boolean. Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784181 Share on other sites More sharing options...
silverglade Posted March 13, 2009 Author Share Posted March 13, 2009 great thank you for the code i will look at it some more. thank you everyone for your help and making this site newbie friendly. i have a long way to go. (sigh). but thank you. derek Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784211 Share on other sites More sharing options...
Maq Posted March 13, 2009 Share Posted March 13, 2009 great thank you for the code i will look at it some more. thank you everyone for your help and making this site newbie friendly. i have a long way to go. (sigh). but thank you. derek We all start somewhere, and that's what this site is for anyway. Quote Link to comment https://forums.phpfreaks.com/topic/149306-solved-simple-contact-form-emailer-not-working/#findComment-784212 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.