October 16, 201313 yr Hi, I have a relatively simple contact form but some of the fields are not submitting any info entered. I'm puzzled because I've used this method several times successfully but for some reason the Name, Phone and Email fields are not working. Yet the enquiry field is!!!??Here's the html and php I'm using: <?php $EmailFrom = "I put the company name here"; $EmailTo = "this is the email address to send the form to"; $Subject = "Website Consultation Enquiry"; $Name = Trim(stripslashes($_POST['Name'])); $Telephone = Trim(stripslashes($_POST['Telephone'])); $Emailaddress = Trim(stripslashes($_POST['Emailaddress'])); $Enquiry = Trim(stripslashes($_POST['Enquiry'])); // prepare email body text $Body = ""; $Body .= "EmailFrom: "; $Body .= $EmailFrom; $Body .= "\n"; $Body .= "Subject: "; $Body .= $Subject; $Body .= "\n"; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Emailaddress: "; $Body .= $Emailaddress; $Body .= "\n"; $Body .= "Telephone: "; $Body .= $Telephone; $Body .= "\n"; $Body .= "Enquiry: "; $Body .= $Enquiry; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=consultationsent.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=messagenotsenttwh.html\">"; function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } } ?> And the HTML form: <form method="post" id="theform" action="consultation.php"> <fieldset> <p> Your Name:<br /> <input type="text" class="txt" id="Name"/> </p> <p> Telephone Number:<br /> <input type="text" class="txt" id="Telephone"/> </p> <p> Email Address:<br /> <input type="text" name="Emailaddress" id="Emailaddress" class="txt"/> </p> <p> Additional information:<br /> <textarea name="Enquiry" type="txt" id="Enquiry"/></textarea> </p><p id="error">Please complete all fields before submitting.</p> <div id="submitbtns"> <p> <input type="submit" value="Submit" style="height: 25px; width: 247px"/> </p> <p> <input type="reset" value="Reset" style="height: 25px; width: 247px"/></p> </div> </fieldset> </form> There is a javascript validation on this form but I don't think it's that or should I post that too???Thanks for any advice.
October 16, 201313 yr your HTML form is incorrect try this <form method="post" id="theform" action="consultation.php"> <fieldset> <p> Your Name: <br /> <input type="text" class="txt" id="Name" name="Name" /> </p> <p> Telephone Number: <br /> <input type="text" class="txt" id="Telephone" name="Telephone" /> </p> <p> Email Address: <br /> <input type="text" name="Emailaddress" id="Emailaddress" class="txt" /> </p> <p> Additional information: <br /> <textarea name="Enquiry" type="txt" id="Enquiry" /></textarea> </p> <p id="error">Please complete all fields before submitting.</p> <div id="submitbtns"> <p> <input type="submit" value="Submit" style="height: 25px; width: 247px" /> </p> <p> <input type="reset" value="Reset" style="height: 25px; width: 247px" /> </p> </div> </fieldset> </form>But i cant see why the email would not work maybe add the JS Edited October 16, 201313 yr by D4Y0
October 16, 201313 yr Author But this html has worked previously. I'm not clear how it's not working.
October 16, 201313 yr you was not giving the html input a name attribute so for example $_POST['Emailaddress'] was not being set unless you are using JS to post the form if so you will need to post that up, or even better a link to the contact form would be easier
October 16, 201313 yr But this html has worked previously. I'm not clear how it's not working. Btw you need a lowercase T on the word trim in your PHP even tho it will work both ways its good to get into a habit of not using uppercase letters in built in php functions.
October 17, 201313 yr Btw you need a lowercase T on the word trim in your PHP even tho it will work both ways its good to get into a habit of not using uppercase letters in built in php functions. ...except for a capital L in Location as in header( "Location: $thankyouurl" ); which doesn't seem to work with a lower case l !
October 20, 201313 yr ...except for a capital L in Location as in header( "Location: $thankyouurl" ); which doesn't seem to work with a lower case l ! Yes this is an exception
Create an account or sign in to comment