Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Location
    Halifax, Nova Scotia, Canada
    Posts
    392
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Very Simple Contact Form Problem... Probably a 2 minute solution! Help Appreciated.

    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:

    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:
    Code:
    <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
    Once I thought I was wrong but I was mistaken.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    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 -

    PHP Code:
    ini_set("display_errors""1");
    error_reporting(E_ALL); 
    The "undefined" variable messages indicate the program variables that you will need to change.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •