Link to home
Start Free TrialLog in
Avatar of isaacr25
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.
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Hi again isaac.

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.
Avatar of isaacr25
isaacr25

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(images/1_bg2.gif) 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=" &nbsp;your name"  >
                                                <br><input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                <br><input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                <br><textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;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>
Your form opening tag should go before your first input tag
gamebits,

I've tried that with no success:

<td valign="top" width="253" height="241" style="background:url(images/1_bg2.gif) 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=" &nbsp;your name"  >
                                                    <br>
                                                    <input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                    <br>
                                                    <input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                    <br>
                                                    <textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;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>
<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.
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.
Did you move the form tag up so that it appears before all the input tags?
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=" &nbsp;your name"  >
                                                    <br>
                                                    <input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                    <br>
                                                    <input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                    <br>
                                                    <textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;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>
So what happens now?  Does the email send when the form is submitted or when the page is loaded?
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?
Contact.php is a separate php file that resides in the same directory.
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You deserve it. Thanks!