PHP form sends blank variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • connie murray
    New Member
    • Jan 2012
    • 4

    PHP form sends blank variables

    Hi, I'm really new to PHP so please be gentle. I have created a contact form for a friend but when I submit the form - it goes to the right address but all of the variables are blank.
    I'm totally stuck - can anyone help?

    php code is

    Code:
    <?php
    
    $EmailFrom = "info@govandentalcare.co.uk";
    $EmailTo = "conniemurray1@hotmail.com";
    $Subject = "online form";
    $Name = trim(stripslashes($_POST['Name']));
    $Email = trim(stripslashes($_POST['Email']));
    $Tel = trim(stripslashes($_POST['Tel']));
    $Message = trim(stripslashes($_POST['Message']));
    // validation
    $validationOK=true;
    if (!$validationOK) {
      echo "please check your details";
      header("Location: http://govandentalcare.co.uk/contactjan.php");
      exit;
    }
    
    // prepare email body text
    
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    // redirect to success page
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"1;URL=thanks.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"1;URL=index.php\">";
    }
    ?>
    Last edited by Dormilich; Jan 4 '12, 10:54 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I don't see a form in your code.

    Comment

    • connie murray
      New Member
      • Jan 2012
      • 4

      #3
      Sorry - here's the html - thanks for any help you can give me

      Code:
        <form action="contactjan.php" method="post">
      
            <p>
              <input type="text" name="name" 
       value="Your Name" size="20" 
       onFocus="this.value=''">
              <input type="text" name="email" 
       value="Email Address" size="20" 
       onFocus="this.value=''">
              <input type="text" name="telephone" 
       value="Telephone Number" size="20" 
       onFocus="this.value=''">
            </p>
            <p>
              <textarea name="message" cols="25" rows="2" onfocus="this.value=''">Your Message</textarea>
            </p>
            <p><br />
              <input name="send" type="submit" class="formbox" id="send" value="Submit" />
            </p>
          </form>

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        Now its obvious why it doesn't work.

        When you submit your form with input field like this:

        Code:
        <input type="text" name="email">
        to retrieve submitted value in php you should do:

        Code:
        $_POST['email']
        instead of

        Code:
        $_POST['Email']
        input field name and $_POST key must match.

        Comment

        • connie murray
          New Member
          • Jan 2012
          • 4

          #5
          Thanks Zorgi for your super quick response but I think I must still hjave something wrong as it's still not working - It emails back just this

          name:
          tel:
          email:
          message:


          HTML is

          Code:
            <form action="contactjan.php" method="post">
            <input type="text" name="name" class="formbox" onfocus="this.value=''" value="name" />
          
                <input type="text" name="tel" class="formbox" onfocus="this.value=''" value="tel" />
                      <input type="text" name="email" class="formbox" onfocus="this.value=''" value="email" />
          <textarea rows="3" name="message" class="formbox" onfocus="this.value=''">message</textarea>
                <p><br />
                  <input name="send" type="submit" class="formbox" id="send" value="Submit" />
                </p>
              </form>

          and PHP

          Code:
          <?php
          
          $EmailFrom = "conniemurray1@hotmail.com";
          $EmailTo = "conniemurray1@hotmail.com";
          $Subject = "contactform";
          $Name = Trim(stripslashes($_POST['name']));
          $Email = Trim(stripslashes($_POST['email']));
          $Tel = Trim(stripslashes($_POST['tel']));
          $Message = Trim(stripslashes($_POST['message']));
          // validation
          $validationOK=true;
          if (!$validationOK) {
            echo "please check your details";
            header("Location:http://govandentalcare.co.uk/contactjan.php");
            exit;
          }
          
          // prepare email body text
          
          $Body = "";
          $Body .= "name: ";
          $Body .= $name;
          $Body .= "\n";
          $Body .= "tel: ";
          $Body .= $tel;
          $Body .= "\n";
          $Body .= "email: ";
          $Body .= $email;
          $Body .= "\n";
          $Body .= "message: ";
          $Body .= $message;
          $Body .= "\n";
          
          // send email
          $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
          
          // redirect to success page
          if ($success){
            print "<meta http-equiv=\"refresh\" content=\"1;URL=thanks.html\">";
          }
          else{
            print "<meta http-equiv=\"refresh\" content=\"1;URL=thanks.html\">";
          }
          ?>
          which is saved from Notepad.

          Sorry to be a pain but this is driving me mad
          Thanks
          CX

          Comment

          • connie murray
            New Member
            • Jan 2012
            • 4

            #6
            Oh wait - now I see what you mean! Thanks so much - got it sorted and would never have managed it without your help.

            Comment

            Working...