View Full Version : Very Simple Contact Form Problem... Probably a 2 minute solution! Help Appreciated.

Tristan Gray
09-04-2009, 07:38 PM

I am just trying to get the simplest possible contact form running for my friend's charity site, and then I am going to add reCapcha to prevent spam. I know there are more concerns to worry about, but honestly, this site won't get much traffic.

Anyway, it's been a while since I did any of this, and whenever I try to use the form it generates an error claiming I haven't entered my e-mail address even when I have. Please tell me what's up. Here's the mailer.php code:

//variables (change these)

$youremail = "fakey@fake.com";
// your email address

$subject = "Mi Camera, Mi Mundo Web Message";
// the subject of the email

$thankyou = "thankyou.html";
// thank you page

// don't change anything else

;if($email == ""){
No email address added. Please go back.<br/>
;}elseif($name == ""){
No name added. Please go back.<br/>
}elseif($message == ""){
No message added. Please go back.<br/>

$msg = ereg_replace("\\\'", "'", $message);
$msg = ereg_replace('\\\"', "\"", $msg);
$message1 = "from: $name\nemail: $email\nmessage:\n$msg1";

mail($youremail, $subject, $msg, "From: $email\r\nReply-to: $email\r\n");
<meta http-equiv="refresh" content="0; url=<?echo $thankyou;?>"">

And the form code for the page is as follows:

<div id="contactform">
<form action="mailer.php" method="post">
<legend>Required Information</legend>
<label for="name">Name</label>
<input id="name" name="name" type="text"><br/>
<label for="email">Email addess</label>
<input id ="email" name="email" type="text"><br/>
<label for="message">Message</label>
<textarea id="message" name="message" cols="40" rows="5"></textarea><br/>
<input class ="submit" type="submit" value="Send Message"><br/>

I know that any seasoned eye can probably solve this problem in 2 minutes so I implore you to help us all out.

Thanks to all those who attempt/respond.


09-04-2009, 07:47 PM
The code is dependent on an old depreciated and soon to be completely removed php feature, register_globals.

You need to reference the form data using $_POST variables, i.e. $_POST['email'] instead of $email

If you add the following two lines of code immediately after your first opening <?php tag, you will see all the php detected errors -

ini_set("display_errors", "1");

The "undefined" variable messages indicate the program variables that you will need to change.