• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Help on php contact form script

Star7

New Member
I used this script on my previous site and it worked, however, it is not working for me now.

contactme.html
Code:
<form method="post" action="submit.php">
			  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                <tr bgcolor="#CCCCCC"> 
                  <td colspan="2"><font size="4">Contact Me </font></td>
                </tr>
                <tr> 
                  <td colspan="2">&nbsp;</td>
                </tr>
                <tr> 
                  <td>Name:</td>
                  <td width="91%"><input type="text" name="name" size=35 maxlength=75></td>
                </tr>
                <tr> 
                  <td width="9%">&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr> 
                  <td>Email:</td>
                  <td><input type="text" name="email" size=35 maxlength=75></td>
                </tr>
                <tr> 
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr> 
                  <td>Subject</td>
                  <td><input type="text" name="subject" size=35 maxlength=75></td>
                </tr>
                <tr> 
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr> 
                  <td valign="top">Message:</td>
                  <td><textarea cols=65 rows=10 name="message"></textarea></td>
                </tr>
                <tr> 
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr> 
                  <td>&nbsp;</td>
                  <td><input type="submit" name="Submit" value="Submit"></td>
                </tr>
              </table>
			</form>

submit.php
Code:
<?php
					
					$mailTo = "starseven@gmail.com";
					
					$mailFrom = "From: $name <$email>\n";
					if ($message != "") {
						if (mail($mailTo, $subject, $message, $mailFrom)) {
							echo "Thank you for taking the trouble to send me your message";
						}
					} else {
						echo "Opps, I just detected an empty message! Go back to the <a href=\"javascript:history.go(-1)\">previous page</a> and try again! Thank you.";
					}
					?>

Here's the page that I had on my site:
http://www.fu-singapore.uni.cc/contactme.html

Problem
It doesn't seem to be going into the if ($message != "") loop, which I don't understand, no matter what I type, it will still take message = "".

All help appreciated.
 
Your previous site probably had REGISTER_GLOBALS set, (which is generally considered a bad practice). You have to reference form variables by either $_POST or $_REQUEST arrays.

submit.php
PHP:
$mailTo = "starseven@gmail.com";
$mailFrom = "From: ".$_POST['name']." <".$_POST['email'].">\n";
if ($_POST['message'] != "") {
	if (mail($mailTo, $_POST['subject'], $_POST['message'], $mailFrom)) {
		echo "Thank you for taking the trouble to send me your message";
	}
} else {
	echo "Opps, I just detected an empty message! Go back to the <a href=\"javascript:history.go(-1)\">previous page</a> and try again! Thank you.";
}
 
Back
Top