...

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



Tristan Gray
09-04-2009, 06:38 PM
Hello,

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:


<?php
//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/>
<?php
;}elseif($name == ""){
?>
No name added. Please go back.<br/>
<?php
}elseif($message == ""){
?>
No message added. Please go back.<br/>
<?php
;}else{

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

And the form code for the page is as follows:


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

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.

Tristan

CFMaBiSmAd
09-04-2009, 06: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");
error_reporting(E_ALL);

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum