March 15, 201016 yr Hi all, wonder if you can help me. I'm new to websites etc... I've put together a website for work and i've got a contact us page with a PHP file to email me the form when completed, this is all working but when i get the email its not showing any other the entered text. I beleive the words have to be the same in the form as to the PHP, i have checked all this, spelling and upper/lower case but still nothing. Can anyone please help me. Thanks.
March 15, 201016 yr Author PHP scrip below. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "info@test.com"; $Subject = "Website Enquiry"; $Name = Trim(stripslashes($_POST['name'])); $Contact_Number = Trim(stripslashes($_POST['number'])); $Email = Trim(stripslashes($_POST['email'])); $Message = Trim(stripslashes($_POST['message'])); // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Contact Number: "; $Body .= $number; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ThankYoue.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=Error.html\">"; } ?>
March 15, 201016 yr PHP scrip below. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "info@test.com"; $Subject = "Website Enquiry"; $Name = Trim(stripslashes($_POST['name'])); $Contact_Number = Trim(stripslashes($_POST['number'])); $Email = Trim(stripslashes($_POST['email'])); $Message = Trim(stripslashes($_POST['message'])); // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Contact Number: "; $Body .= $number; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ThankYoue.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=Error.html\">"; } ?> Ok one reason might be is ur not checking if the form is even filled in first so its just going to send blank values right when you run the script unless you check to make sure the form has been submmitted first.
March 16, 201016 yr PHP variable names are case sensitive. $Email is NOT the same as $email. Make sure the variable names match exactly.
March 16, 201016 yr Author Thanks for your replies. I have checked the names for and they are all in the same case format. Where should i go from here? Thanks for you help guys.
March 16, 201016 yr To stop the form from submitting empty values on page load, put an if statement around your script like so: <?php if ($_POST){ // form processing code goes here } ?> Good luck
March 16, 201016 yr I have checked the names for and they are all in the same case format. OK - it's just that in the PHP snippet you posted, the casing was different: $Email = Trim(stripslashes($_POST['email'])); $Body .= $email; But assuming you've corrected this... what webdesigner93 and notbanksy said!
March 17, 201016 yr If you post the HTML for the form which is used for the submission, I'll try to fix it up for you.
March 20, 201016 yr Author If you post the HTML for the form which is used for the submission, I'll try to fix it up for you. Hi Andy, See below which is different to the PHP above. HTML <table width="450" border="0" align="left" id="ContactUs"> <tr> <td width="120" align="left">Forename</td> <td width="325" align="left"><form id="form1" name="form1" method="post" action=""> <input type="text" name="forname" id="forname" /> </form></td> </tr> <tr> <td width="120" align="left">Surname</td> <td align="left"><form id="form2" name="form2" method="post" action=""> <label> <input type="text" name="surname" id="surname" /> </label> </form></td> </tr> <tr> <td width="120" align="left">Company Name</td> <td align="left"><form id="form3" name="form3" method="post" action=""> <label> <input type="text" name="companyname" id="companyname" /> </label> </form></td> </tr> <tr> <td width="120" align="left">Email</td> <td align="left"><form id="form4" name="form4" method="post" action=""> <label> <input type="text" name="email" id="email" /> </label> </form></td> </tr> <tr> <td width="120" align="left"><form id="form5" name="form5" method="post" action="send_eNewsletter.php"> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> </form></td> <td align="left"> </td> </tr> </table> PHP <?php $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "mdainty85@o2.co.uk"; $Subject = "eNewsletter Subscription"; $Forename = Trim(stripslashes($_POST['forename'])); $Surname = Trim(stripslashes($_POST['surname'])); $Company_Name = Trim(stripslashes($_POST['companyname'])); $Email = Trim(stripslashes($_POST['email'])); $Body = ""; $Body .= "Forename: "; $Body .= $forename; $Body .= "\n"; $Body .= "Surname: "; $Body .= $surname; $Body .= "\n"; $Body .= "Company Name: "; $Body .= $companyname; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ThankYoueNewsletter.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=Error.html\">"; } ?>
March 21, 201016 yr Your problem is the HTML - you have wrapped each form input in its own form! Obviously you should only have one set of <form></form> tags, which should enclose the entire form.
March 22, 201016 yr Try this HTML, replace all your current HTML with this: <form id="newsletterForm" name="newsletterForm" method="post" action="send_eNewsletter.php"> <table width="450" border="0" align="left" id="ContactUs"> <tr> <td width="120" align="left">Forename</td> <td width="325" align="left"> <input type="text" name="forename" id="forename" /> </td> </tr> <tr> <td width="120" align="left">Surname</td> <td align="left"> <input type="text" name="surname" id="surname" /> </td> </tr> <tr> <td width="120" align="left">Company Name</td> <td align="left"> <input type="text" name="companyname" id="companyname" /> </td> </tr> <tr> <td width="120" align="left">Email</td> <td align="left"> <input type="text" name="email" id="email" /> </td> </tr> <tr> <td width="120" align="left"> <input type="submit" name="Submit" id="Submit" value="Submit" /> </td> <td align="left"> </td> </tr> </table> </form> There's now only 1 form tag, invalid tags have been removed and a couple of spelling mistakes cleared up which would stop the PHP script working as expected. Remember to +1 if it helps
March 22, 201016 yr Hi Andy, See below which is different to the PHP above. HTML <table width="450" border="0" align="left" id="ContactUs"> <tr> <td width="120" align="left">Forename</td> <td width="325" align="left"><form id="form1" name="form1" method="post" action=""> <input type="text" name="forname" id="forname" /> </form></td> </tr> <tr> <td width="120" align="left">Surname</td> <td align="left"><form id="form2" name="form2" method="post" action=""> <label> <input type="text" name="surname" id="surname" /> </label> </form></td> </tr> <tr> <td width="120" align="left">Company Name</td> <td align="left"><form id="form3" name="form3" method="post" action=""> <label> <input type="text" name="companyname" id="companyname" /> </label> </form></td> </tr> <tr> <td width="120" align="left">Email</td> <td align="left"><form id="form4" name="form4" method="post" action=""> <label> <input type="text" name="email" id="email" /> </label> </form></td> </tr> <tr> <td width="120" align="left"><form id="form5" name="form5" method="post" action="send_eNewsletter.php"> <label> <input type="submit" name="Submit" id="Submit" value="Submit" /> </label> </form></td> <td align="left"> </td> </tr> </table> PHP <?php $EmailFrom = Trim(stripslashes($_POST['email'])); $EmailTo = "mdainty85@o2.co.uk"; $Subject = "eNewsletter Subscription"; $Forename = Trim(stripslashes($_POST['forename'])); $Surname = Trim(stripslashes($_POST['surname'])); $Company_Name = Trim(stripslashes($_POST['companyname'])); $Email = Trim(stripslashes($_POST['email'])); $Body = ""; $Body .= "Forename: "; $Body .= $forename; $Body .= "\n"; $Body .= "Surname: "; $Body .= $surname; $Body .= "\n"; $Body .= "Company Name: "; $Body .= $companyname; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ThankYoueNewsletter.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=Error.html\">"; } ?> sorry for interrupting but shouldnt this be $Body .= $surname; this $Body .= $Surname; i think the case of most of ur variables arent matching
March 22, 201016 yr sorry for interrupting but shouldnt this $Body .= $surname; be this $Body .= $Surname; i think the case of most of ur variables arent matching Yeah that's what I kept saying too! The message didn't seem to get through though...
March 23, 201016 yr Author Thank you very much for you help guys, my forms are now working with your help. Sorry if i was a bit slow at correcting some issues but I am new to this and do not fully understand its workings. Thanks again. Mart
Create an account or sign in to comment