Results 1 to 3 of 3

Thread: problem with POST contact form

  1. #1
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default problem with POST contact form

    This is my first attempt at writing a contact form using php.
    The form displays (you can see it online here), but it simply clears the fields when submitted - which leads me to suspect that the POST data is not being sent.
    Any suggestions would be helpful.
    PHP Code:
    <?php if(!isset($_POST['email'])) { ?>
        <div>
            Please send me a message.  
            I will be happy to answer your questions.
        </div>
        <form method="POST" class="cssform">
            <p>
                To: Adrian
            </p>
            <p>
                <label for="user">From: </label>
                <input type="text" id="user" value="">
            </p>
            <p>
                <label for="email">Email: </label>
                <input type="text" id="email" value="">
            </p>
            <p>
                <label for="subject">Subject: </label>
                <input type="text" id="subject" value="Reel Lumber Website Demo">
            </p>
            <p>
                <label for="message">Question/ Comment: </label>
                <textarea rows="10" cols="45" id="message"></textarea>
            </p>
            <p>
                <input type="submit" value="Send Message" id="B1">
            </p>
        </form><?php
    } else {
        echo 
    '<h3>Sending message</h3><br>Please wait<br><br>';
        
        
    $userIP = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
        
    $eMail ''//email edited out
        
    $userName $_POST['user'];
        
    $userEmail $_POST['email'];
        
    $subject $_POST['subject'];
        
    $message $_POST['message'];
        
        
    $OKuserName filter_var($userNamefilter_sanitize_string);
        
    $cleanUserEmail filter_var($userEmailfilter_sanitize_email);
        if(
    filter_var($cleanUserEmailfilter_validate_email)) {
            
    $OKuserEmail $cleanUserEmail;
        } else {
            echo 
    'Invalid email address : <a href="contactme.php">please try again</a>';
        }
        
    $OKsubject filter_var($subjectfilter_sanitize_string);
        
    $OKmessage filter_var($messagefilter_sanitize_string);
        
        if(
    mail('Adrian <'.$email.'>',
            
    $OKsubject$OKmessage,
            
    'Return-Path: "'.$OKuserName.'" <'.$OKuserEmail.">\n"
            
    .'From: "'.$OKuserName.'" <'.$OKuserEmail.">\n"
            
    .'Reply-To: "'.$OKuserName.'" <'.$OKuserEmail.">\n"
            
    ."X-Mailer: PHP/".phpversion()."\n"
            
    ."X-From-IP: ".$userIP)) {
            echo 
    '<h3>Message Sent Successfully</h3><br>Thank you.  I will reply as soon as possible.';
        } else {
            echo 
    '<h3>Unable to Send Message</h3><br><a href="contactme.php">please try again</a>';
        }
    }
    the script is loosely based on this one, which works just fine:
    PHP Code:
    <?php if( ! isset( $_POST["EMail"] ) ) { ?>

    <div>
    Send me your questions or comments by using this form.  I'll answer as soon as possible.
    </div>
    <form method="POST" name="MailForm">
      <div align="center">
        <center>
        <table border="0" cellpadding="4" cellspacing="0">
          <tr>
            <td valign="top" align="right">To:</td>
            <td>

    <?php

      
    //  Display Menu if More than one name
      
    if( count$eMail ) > ) {
        echo 
    "<select size=\"1\" name=\"To\">\n";

        foreach( 
    $eMail as $k => $a )
            echo 
    "<option value=\"$k\">$a[0]</option>\n";
        echo 
    "</select>\n";
       } else
         echo 
    $eMail[0][0];

    ?>
            </td>
          </tr>
          <tr>
            <td valign="top" align="right">From:</td>
            <td><input type="text" name="From" size="44" maxlength="32"></td>
          </tr>
          <tr>
            <td valign="top" align="right">E-Mail:</td>
            <td><input type="text" name="EMail" size="44"></td>
          </tr>
          <tr>
            <td valign="top" align="right">Subject: </td>
            <td>
              <p align="center"><input type="text" name="Subject" size="44"></td>
          </tr>
        </table>
        </center>
      </div>
      <p align="center"><textarea rows="10" name="Body" cols="45"></textarea></p>
      <p align="center"><input type="submit" value="Send" name="B1"></p>
    </form>

    <?php
     
    } else {

       echo 
    "<B>Attempting to send message</b></BR></BR>\n";

       
    $userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

       if( 
    count$eMail ) == )
        
    $_POST["To"] = "0";

       if( 
    mail'"' $eMail[$_POST["To"]][0] . '" <' $eMail[$_POST["To"]][1] . '>',
           
    $_POST["Subject"], $_POST["Body"],
           
    'Return-Path: "' $_POST["From"] . '" <' $_POST["EMail"] . ">\n"
           
    'From: "' $_POST["From"] . '" <' $_POST["EMail"] . ">\n"
           
    'Reply-To: "' $_POST["From"] . '" <' $_POST["EMail"] . ">\n"
           
    "X-Mailer: PHP/" phpversion() . "\n"
           
    "X-From-IP: " $userip ) )
         echo 
    "Message Sent Successfully";
      else
          echo 
    "UNABLE To Send Message.";
    }
    ?>
    Edit: " var_dump($_POST) " returns " array(0){} ", so the POST data is not being sent. Any suggestions on what to troubleshoot next? thanks
    Last edited by traq; 05-26-2009 at 01:45 PM.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    have you tried giving the form an action?

    Code:
    action="<?php echo $PHP_SELF;?>"
    oo possibly ignore that

    id's arent what the php is reading with the $_POST['email'] it's looking for the name.

    so this <input type="text" id="user" value="">
    should be <input type="text" id="user" name="user" value="">

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    ^that's it. works with names. thanks a bunch, man.

Bookmarks

Posting Permissions

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