isaacr25
asked on
Help with html/php contact form
I'm having trouble with a contact form on a website. Please visit this site: www.mwebdev.com/par and go to the Contact Us page. I have a contact.php form set up with the correct field names etc. The same php file works on other sites, but I can't get it to work here. Its supposed to go to a Message Sent page when the message is submitted. Neither the Reset or Submit buttons work. Thanks in advance.
ASKER
Here is the php code:
<?php
// get posted data into local variables
$EmailFrom = "-removed-";
$EmailTo = "-removed-";
$Subject = "-removed-";
$Name = Trim(stripslashes($_POST[' Name']));
$Phone = Trim(stripslashes($_POST[' Phone']));
$Email = Trim(stripslashes($_POST[' Email']));
$Message = Trim(stripslashes($_POST[' Message']) );
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\ ">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$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=sent.html\ ">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\ ">";
}
?>
And here is the form code:
<td valign="top" width="253" height="241" style="background:url(imag es/1_bg2.g if) repeat-x top; background-color:#7F95AE "> <div style=" margin:24 0 0 21px; line-height:14px " class="w"><input name="Name" type="text" class="w" id="Name" style="width:210px; height:25px; " value=" your name" >
<br><input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br><input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br><textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> message</textarea>
</div>
<form action="" id="form" style="margin:0; padding:0 ">
<div style="margin:12 15 0 88px;"><input name="clear" type="image" id="clear" style=" border-style:none " src="images/6_k1.gif" onClick="this.form.reset() ; return false;"><input name="submit" type="image" id="submit" style="border-style:none; margin-left:16px " src="images/6_k2.gif" >
</div>
</form>
</td>
<?php
// get posted data into local variables
$EmailFrom = "-removed-";
$EmailTo = "-removed-";
$Subject = "-removed-";
$Name = Trim(stripslashes($_POST['
$Phone = Trim(stripslashes($_POST['
$Email = Trim(stripslashes($_POST['
$Message = Trim(stripslashes($_POST['
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$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=sent.html\
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\
}
?>
And here is the form code:
<td valign="top" width="253" height="241" style="background:url(imag
<br><input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br><input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br><textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> message</textarea>
</div>
<form action="" id="form" style="margin:0; padding:0 ">
<div style="margin:12 15 0 88px;"><input name="clear" type="image" id="clear" style=" border-style:none " src="images/6_k1.gif" onClick="this.form.reset()
</div>
</form>
</td>
Your form opening tag should go before your first input tag
ASKER
gamebits,
I've tried that with no success:
<td valign="top" width="253" height="241" style="background:url(imag es/1_bg2.g if) repeat-x top; background-color:#7F95AE "> <div style=" margin:24 0 0 21px; line-height:14px " class="w"><form action="" id="form" style="margin:0; padding:0 ">
<div align="center">
<input name="Name" type="text" class="w" id="Name" style="width:210px; height:25px; " value=" your name" >
<br>
<input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br>
<input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br>
<textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> message</textarea>
</div>
</div>
<div style="margin:12 15 0 88px;">
<div align="center">
<input name="clear" type="image" id="clear" style=" border-style:none " src="images/6_k1.gif" onClick="this.form.reset() ; return false;">
<input name="submit" type="image" id="submit" style="border-style:none; margin-left:16px " src="images/6_k2.gif" >
</div>
</div>
</form> </td>
I've tried that with no success:
<td valign="top" width="253" height="241" style="background:url(imag
<div align="center">
<input name="Name" type="text" class="w" id="Name" style="width:210px; height:25px; " value=" your name" >
<br>
<input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br>
<input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br>
<textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> message</textarea>
</div>
</div>
<div style="margin:12 15 0 88px;">
<div align="center">
<input name="clear" type="image" id="clear" style=" border-style:none " src="images/6_k1.gif" onClick="this.form.reset()
<input name="submit" type="image" id="submit" style="border-style:none; margin-left:16px " src="images/6_k2.gif" >
</div>
</div>
</form> </td>
<form action=""
There needs to be a form action. Either it points to the script if the script is in a separate file or it points to the same file as the form if the script is embedded in that file.
There needs to be a form action. Either it points to the script if the script is in a separate file or it points to the same file as the form if the script is embedded in that file.
ASKER
Jason,
I added the name of the php script for the form action, and I'm getting an email now. However, none of the field values are being transmitted in the email.
I added the name of the php script for the form action, and I'm getting an email now. However, none of the field values are being transmitted in the email.
Did you move the form tag up so that it appears before all the input tags?
ASKER
Yes,
Here's my form code now:
<form action="contact.php" id="form" style="margin:0; padding:0 ">
<div align="center">
<input name="Name" type="text" class="w" id="Name" style="width:210px; height:25px; " value=" your name" >
<br>
<input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br>
<input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br>
<textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> message</textarea>
</div>
<div style="margin:12 15 0 88px;"><input name="clear" type="image" id="clear" style=" border-style:none " src="images/6_k1.gif" onClick="this.form.reset() ; return false;"><input name="submit" type="image" id="submit" style="border-style:none; margin-left:16px " src="images/6_k2.gif" >
</div>
</form>
Here's my form code now:
<form action="contact.php" id="form" style="margin:0; padding:0 ">
<div align="center">
<input name="Name" type="text" class="w" id="Name" style="width:210px; height:25px; " value=" your name" >
<br>
<input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br>
<input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br>
<textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> message</textarea>
</div>
<div style="margin:12 15 0 88px;"><input name="clear" type="image" id="clear" style=" border-style:none " src="images/6_k1.gif" onClick="this.form.reset()
</div>
</form>
So what happens now? Does the email send when the form is submitted or when the page is loaded?
ASKER
The email sends, but with no values, only the field labels from the php file. The php file is being run correctly, but the field values aren't being sent in the email.
Are the files separate or is the php embedded in the same file as the form?
ASKER
Contact.php is a separate php file that resides in the same directory.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You deserve it. Thanks!
There is almost no way to troubleshoot this without the php and html code involved.
As a wild guess, I would point towards using images as buttons and the php script is not detecting the submit properly.