Jump to content

Very simple contact form help


Nakoma

Recommended Posts

Hi All,

 

Sorry for my limited knowledge of PHP was wondering if someone could help.

 

Making a simple contact form and its not working and can't figuire out why here's the form.

 

                                    <td style="height:370px;"><table border="0" cellpadding="0" cellspacing="0" style="height:100%;">

                                        <tr>

                                          <td style="width:1px; height:100%; background-color:#929292"><img src="images/spacer.gif" width="1" height="1" alt=""></td>

                                          <td><img src="images/spacer.gif" width="21" height="1" alt=""></td>

                                          <td style="width:330px;"><form method="POST" action="mycontactphp.php">

                                              <table border="0" cellpadding="0" cellspacing="0" style="width:321px;">

                                                <tr>

                                                  <td><img src="images/6title3.jpg" alt="" style="margin-bottom:8px;"></td>

                                                </tr>

                                                <tr>

                                                  <td class="ins">If you have any enquiries you can contact us by completing and submitting the form below. </td>

                                                </tr>

                                                <tr>

                                                  <td><img src="images/spacer.gif" width="1" height="13" alt=""></td>

                                                </tr>

                                                <tr>

                                                  <td><table border="0" cellpadding="0" cellspacing="0">

                                                      <tr>

                                                        <td style="width:78px; height:20px; padding-top:5px;">Your name:</td>

                                                        <td><input type="text" name="YourName"></td>

                                                      </tr>

                                                  </table></td>

                                                </tr>

                                                <tr>

                                                  <td><img src="images/spacer.gif" width="1" height="10" alt=""></td>

                                                </tr>

                                                <tr>

                                                  <td><table border="0" cellpadding="0" cellspacing="0">

                                                      <tr>

                                                        <td style="width:78px; height:20px; padding-top:5px;">Phone:</td>

                                                        <td><input type="text" name="Phone"></td>

                                                      </tr>

                                                  </table></td>

                                                </tr>

                                                <tr>

                                                  <td><img src="images/spacer.gif" width="1" height="8" alt=""></td>

                                                </tr>

                                                <tr>

                                                  <td><table border="0" cellpadding="0" cellspacing="0">

                                                      <tr>

                                                        <td style="width:78px; height:20px; padding-top:5px;">E-mail: </td>

                                                        <td><input type="text" name="EmailFrom"></td>

                                                      </tr>

                                                  </table></td>

                                                </tr>

                                                <tr>

                                                  <td><img src="images/spacer.gif" width="1" height="8" alt=""></td>

                                                </tr>

                                                <tr>

                                                  <td><table border="0" cellpadding="0" cellspacing="0">

                                                  </table></td>

                                                </tr>

                                                <tr>

                                                  <td><img src="images/spacer.gif" width="1" height="8" alt=""></td>

                                                </tr>

                                                <tr>

                                                  <td><table border="0" cellpadding="0" cellspacing="0">

                                                      <tr>

                                                        <td style="width:78px; height:20px; padding-top:5px;">Your message:</td>

                                                        <td><textarea name="YourMessage" textarea style="overflow:auto;" cols="5" rows="10"></textarea></td>

                                                      </tr>

                                                  </table></td>

                                                </tr>

                                                <tr>

                                                  <td><table border="0" cellpadding="0" cellspacing="0" style="margin:10px 0 0 100px;" class="kn">

                                                      <tr>

                                                        <td style="width:44px;"><img src="images/ch_11.gif" style="margin-right:3px; float:left; margin-top:5px;" alt=""><a href="#" onClick="document.getElementById('form').reset()">clear</a></td>

                                                        <td><img src="images/ch_11.gif" style="margin-right:3px; float:left; margin-top:5px;" alt=""><a href="#" onClick="document.getElementById('form').submit()">submit</a></td>

                                                      </tr>

                                                  </table></td>

                                                </tr>

                                              </table>

 

Here's the PHP script mycontactphp.php

 

<?php

 

// get posted data into local variables

$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));

$EmailTo = "[email protected]";

$Subject = "New query from website"

$YourName = Trim(stripslashes($_POST['YourName']));

$Phone = Trim(stripslashes($_POST['Phone']));

$YourMessage = Trim(stripslashes($_POST['YourMessage']));

 

// validation

$validationOK=true;

if (Trim($EmailFrom)=="") $validationOK=false;

if (!$validationOK) {

  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

  exit;

}

 

// prepare email body text

$Body = "";

$Body .= "YourName: ";

$Body .= $YourName;

$Body .= "\n";

$Body .= "Phone: ";

$Body .= $Phone;

$Body .= "\n";

$Body .= "YourMessage: ";

$Body .= $YourMessage;

$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=ok.htm\">";

}

else{

  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

}

?>

 

 

Can someone please put me out of my misery thank you !

Link to comment
https://forums.phpfreaks.com/topic/91553-very-simple-contact-form-help/
Share on other sites

First, in mycontactphp.php, add the semicolon to the end of the $Subject line.

 

$Subject = "New query from website";

 

Second, your form page is really hard to read with all those opening and closing tables, and your "Submit" line has me mystified.

 

I used this, and it worked as expected:

<form method="POST" action="mycontactphp.php">
Your name:<input type="text" name="YourName"><br />
Phone:<input type="text" name="Phone"><br />
E-mail: <input type="text" name="EmailFrom"><br />
Your message:<textarea name="YourMessage"></textarea><br />
<input type="submit" value="Submit Data"><br />

 

Once you have the code working, you can work on making the page pretty.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.