PDA

View Full Version : Help on php contact form script



Star7
July 12th, 2008, 21:58
I used this script on my previous site and it worked, however, it is not working for me now.

contactme.html

<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

<?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.

Tree
July 13th, 2008, 02:18
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

$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.";
}

iBrightDev
July 13th, 2008, 02:33
u should probably search the forum for other threads that might already answer your question, or provide you with what you already need ;)

http://freewebspace.net/forums/showthread.php?t=2209997

Star7
July 13th, 2008, 19:35
Thanks for everything tree. I will check out your codes method.

iBrightDev
July 13th, 2008, 21:23
no problem. hope something here helps you. :P