Nakoma Posted February 17, 2008 Share Posted February 17, 2008 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 = "help@mywebsiteaddress.co.uk"; $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 ! Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted February 17, 2008 Share Posted February 17, 2008 What exactly isn't working? Do you get an error message? Quote Link to comment Share on other sites More sharing options...
Nakoma Posted February 17, 2008 Author Share Posted February 17, 2008 Basically it runs the PHP script but doens't pass the variables through so returns errors. (see screen shot) Quote Link to comment Share on other sites More sharing options...
Nakoma Posted February 17, 2008 Author Share Posted February 17, 2008 Bump Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted February 18, 2008 Share Posted February 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
Nakoma Posted February 23, 2008 Author Share Posted February 23, 2008 Register Global is set to off so it will never pass through the variables. Thanks for all your help 5 days figuiring it out. How do i get around this, in very simple terms an example if possible so i can then code this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.