PHP Form not working
#1
Posted 15 March 2010 - 09:08 PM
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.
#3
Posted 15 March 2010 - 09:19 PM
<!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\">";
}
?>
#4
Posted 15 March 2010 - 09:54 PM
mcfly01, on 15 March 2010 - 09:19 PM, said:
<!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.
#5
Posted 16 March 2010 - 03:26 AM
#6
Posted 16 March 2010 - 11:01 AM
Where should i go from here?
Thanks for you help guys.
#7
Posted 16 March 2010 - 11:15 AM
<?php
if ($_POST){
// form processing code goes here
}
?>Good luck
#8
Posted 16 March 2010 - 08:35 PM
mcfly01, on 16 March 2010 - 11:01 AM, said:
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!
#9
Posted 17 March 2010 - 12:58 PM
#10
Posted 20 March 2010 - 06:02 PM
andyl, on 17 March 2010 - 12:58 PM, said:
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\">";
}
?>
#11
Posted 21 March 2010 - 11:51 PM
Obviously you should only have one set of <form></form> tags, which should enclose the entire form.
#12
Posted 22 March 2010 - 12:54 AM
<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
#13
Posted 22 March 2010 - 01:26 AM
mcfly01, on 20 March 2010 - 06:02 PM, said:
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
#15
Posted 23 March 2010 - 12:03 PM
Thanks again.
Mart
- ← Five first steps in learning PHP
- Server Side (PHP, Databases, ASP.NET, etc)
- anyone know a good robust contact form solution? →
Help



















