wizpeep Posted October 17, 2008 Share Posted October 17, 2008 Have configured a form handling script to send form result to my email. Sends to the email ok but no form results in email just blank. How can I rectify it????? below is the form and the php code <html><body><font face=Arial size=1> <form method="post" action="contact.php"> <table align=center> <tr><td colspan=2 align=center bgcolor="cccccc"><strong>Enqury Form:</strong></td></tr> <tr><td>Name:</td><td><input size=25 name="Name"></td></tr> <tr><td>Email:</td><td><input size=25 name="Email"></td></tr> <tr><td>Company:</td><td><input size=25 name="Company"></td></tr> <tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> <tr><td>Send Info:<br></td><td><input type="radio" name="list" value="yes"> Yes <input type="radio" name="list" value="no"> No <br></td></tr> <tr><td colspan=2>Message:</td></tr> <tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr> <tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> </table> </form> </body> </html> <?php $to = "info@recruitment4less.co.uk"; $subject = "Recruitment4less Enquiry form"; $Name = $_REQUEST['Name'] ; $Company = $_REQUEST['Company'] ; $Email = $_REQUEST['Email'] ; $Phone = $_REQUEST['Phone'] ; $Brochure = $_REQUEST['Brochure'] ; $Message = $_REQUEST['Message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Wizpeep Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/ Share on other sites More sharing options...
.josh Posted October 17, 2008 Share Posted October 17, 2008 You have your php on your page without checking whether form info was sent or not, so when page first loads, you're going to automatically get an email with a bunch of empty values. Upon form submission you should have been receiving another email with actual stuff. Are you not ending up with 2 emails? Also, use $_POST instead of $_REQUEST Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/#findComment-668131 Share on other sites More sharing options...
DeanWhitehouse Posted October 17, 2008 Share Posted October 17, 2008 Try changing REQUEST to POST, and also do if(isset($_POST['send'])) { //all your code in here (the email bits etc.) } Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/#findComment-668133 Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 <?php // Move the PHP to the top, and check for a POST // I like this method better then checking for $_POST['send'] // as some browsers don't send the submit buttons value if($_SERVER['REQUEST_METHOD'] == 'POST'){ $to = "info@recruitment4less.co.uk"; $subject = "Recruitment4less Enquiry form"; //You don't actually build a message to send??? //Try this: $message = "Name: ".$_POST['Name']."\n". "Company: ". $_POST['Company']."\n". "Email: ". $_POST['Email']."\n". "Phone: ". $_POST['Phone']."\n". "Brochure: ". $_POST['Brochure']."\n". "Message: ". $_POST['Message']; $headers = "From: ".$_POST['email']; $sent = mail($to, $subject, $message, $headers) ; if($sent){ print "Your mail was sent successfully"; exit; }else{ print "We encountered an error sending your mail"; exit; } } ?> <html><body><font face=Arial size=1> <form method="post"> <table align=center> <tr><td colspan=2 align=center bgcolor="cccccc"><strong>Enqury Form:</strong></td></tr> <tr><td>Name:</td><td><input size=25 name="Name"></td></tr> <tr><td>Email:</td><td><input size=25 name="Email"></td></tr> <tr><td>Company:</td><td><input size=25 name="Company"></td></tr> <tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> <tr><td>Send Info:<br></td><td><input type="radio" name="list" value="yes"> Yes <input type="radio" name="list" value="no"> No <br></td></tr> <tr><td colspan=2>Message:</td></tr> <tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr> <tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> </table> </form> </body> </html> ...i also removed the ACTION on the form tag, as it will post to itself by default Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/#findComment-668145 Share on other sites More sharing options...
discomatt Posted October 17, 2008 Share Posted October 17, 2008 DON'T remove the action attribute altogether - it's required by W3 standards... instead, simply use action="" Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/#findComment-668156 Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 DON'T remove the action attribute altogether - it's required by W3 standards... instead, simply use action="" i was not aware, good to know Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/#findComment-668157 Share on other sites More sharing options...
.josh Posted October 17, 2008 Share Posted October 17, 2008 I didn't know that either, though coincidentally I actually do do that when I'm posting to itself. Quote Link to comment https://forums.phpfreaks.com/topic/128874-newbie-form-problem-simple-for-you-budding-gurus/#findComment-668159 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.