$_POST variable isn't collecting values for email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaiwilliams
    New Member
    • Apr 2007
    • 5

    #1

    $_POST variable isn't collecting values for email

    Hi guys,

    I've got the following code:

    <?

    $msg = "E-MAIL SENT FROM www.jaiwilliams .com\n";
    $msg .= "Sender's Name: $_POST[sender_name]\n";
    $msg .= "Sender's E-Mail: $_POST[sender_email]\n";
    $msg .= "Message: $_POST[message]\n\n";

    $to = "jai@jaiwilliam s.com";
    $subject = "Web Site Feedback";
    $mailheaders = "From: My Web Site <www.jaiwilliam s.com> \n";
    $mailheaders .= "Reply-To: $_POST[sender_email]\n\n";

    mail($to, $subject, $msg, $mailheaders);

    ?>


    The emails that come back only include the following:

    E-MAIL SENT FROM www.jaiwilliams .com
    Sender's Name:
    Sender's E-Mail:
    Message:

    Any data that's being input is NEVER captured. What am I doing wrong here?

    Thanks in advance.
    Jai
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Do you have set <form> method to post?
    Try this code, if still have the problem then post your HTML form as well.
    [PHP]<?
    $msg = "E-MAIL SENT FROM www.jaiwilliams .com\n";
    $msg .= "Sender's Name: {$_POST["sender_nam e"]}\n";
    $msg .= "Sender's E-Mail: {$_POST["sender_ema il"]}\n";
    $msg .= "Message: {$_POST["message"]}\n\n";

    $to = "jai@jaiwilliam s.com";
    $subject = "Web Site Feedback";
    $mailheaders = "From: My Web Site <www.jaiwilliam s.com> \n";
    $mailheaders .= "Reply-To: {$_POST["sender_ema il"]}\n\n";

    mail($to, $subject, $msg, $mailheaders);

    ?>[/PHP]

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      The problem is that you were not quoting your identifiers for your $_POST array.

      $_POST[message] will not work, however $_POST['message'] and $_POST["message"] both will. Remember, also, that the key (the name of the element) is case sensitive, so if it is capitalized in your submission form, it must be capitalized in your $_POST array's key name when you try to access it.

      Comment

      • jaiwilliams
        New Member
        • Apr 2007
        • 5

        #4
        Originally posted by mwasif
        Do you have set <form> method to post?
        Try this code, if still have the problem then post your HTML form as well.
        [PHP]<?
        $msg = "E-MAIL SENT FROM www.jaiwilliams .com\n";
        $msg .= "Sender's Name: {$_POST["sender_nam e"]}\n";
        $msg .= "Sender's E-Mail: {$_POST["sender_ema il"]}\n";
        $msg .= "Message: {$_POST["message"]}\n\n";

        $to = "jai@jaiwilliam s.com";
        $subject = "Web Site Feedback";
        $mailheaders = "From: My Web Site <www.jaiwilliam s.com> \n";
        $mailheaders .= "Reply-To: {$_POST["sender_ema il"]}\n\n";

        mail($to, $subject, $msg, $mailheaders);

        ?>[/PHP]

        Hi,

        Thanks for the response. I truly appreciate the assistance. I did try your suggestion, with the included braces and quotations (single and then double) and get the exact same results as before. The code for the form is set to "post" as well. I'm including that code below here for your review:

        <form method="post" action="sendmai l.php">
        <p><b>Bold</b> fields are required. <u>U</u>nderlined letters are accesskeys.</p>

        <fieldset>
        <legend>Persona l Information</legend>
        <label for="firstname" accesskey="f">F irst name: </label>
        <input type="text" id="firstname" name="firstname " tabindex="1" value="" title="first name"><br>
        <label for="lastname" accesskey="l">L ast name: </label>
        <input type="text" id="lastname" name="lastname" tabindex="2" title="last name"><br>
        <label for="email" class="required " accesskey="e">E mail: </label>

        <input type="text" id="email" name="email" tabindex="3" title="email">< br>
        <small>Your email address is safe with us, until we're acquired.</small>
        </fieldset>
        <fieldset>
        <legend>Comment s</legend>
        <label for="comments" accesskey="c">C omments: </label>
        <textarea name="comments" rows="3" cols="23" id="comments" tabindex="4" title="comments "></textarea><br>

        <label for="kludge"></label>
        <input type="submit" value="Send" id="submit" tabindex="5"> <INPUT type="reset" id="reset" tabindex="6">
        </fieldset>
        </form>

        Again, thanks for the code review. This is really about to drive me batty. :)

        Best Regards,
        Jai

        Comment

        • jaiwilliams
          New Member
          • Apr 2007
          • 5

          #5
          Originally posted by Motoma
          The problem is that you were not quoting your identifiers for your $_POST array.

          $_POST[message] will not work, however $_POST['message'] and $_POST["message"] both will. Remember, also, that the key (the name of the element) is case sensitive, so if it is capitalized in your submission form, it must be capitalized in your $_POST array's key name when you try to access it.
          Hello,

          Thanks for taking the time to review my code. I tried quoting the identifiers as suggested, with single quotations and received the following parse error:

          syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

          Making an attempt with double quotations yields the following parse error:

          syntax error, unexpected "" .....

          Please note that each of these attempts was tried without braces. I don't know if that's a factor or not. And I guess that I'm just trying to rationalize here the significance of quoting the identifiers. The PHP book that I have been using as a reference (fast&easy web development) doesn't use quotations in the example code, nor does it allude to using braces either. But hey, I'm obviously a novice - so, what do I know? :)

          Oh, you mentioned something about the key being case sensitive. What do you mean by key? I'm totally missing something here, aren't I? I'm including the form code below as well:

          <form method="post" action="sendmai l.php">
          <p><b>Bold</b> fields are required. <u>U</u>nderlined letters are accesskeys.</p>

          <fieldset>
          <legend>Persona l Information</legend>
          <label for="firstname" accesskey="f">F irst name: </label>
          <input type="text" id="firstname" name="firstname " tabindex="1" value="" title="first name"><br>
          <label for="lastname" accesskey="l">L ast name: </label>
          <input type="text" id="lastname" name="lastname" tabindex="2" title="last name"><br>
          <label for="email" class="required " accesskey="e">E mail: </label>

          <input type="text" id="email" name="email" tabindex="3" title="email">< br>
          <small>Your email address is safe with us, until we're acquired.</small>
          </fieldset>
          <fieldset>
          <legend>Comment s</legend>
          <label for="comments" accesskey="c">C omments: </label>
          <textarea name="comments" rows="3" cols="23" id="comments" tabindex="4" title="comments "></textarea><br>

          <label for="kludge"></label>
          <input type="submit" value="Send" id="submit" tabindex="5"> <INPUT type="reset" id="reset" tabindex="6">
          </fieldset>
          </form>

          Again,

          I really appreciate the code review. I just can't seem to quite make sense of it. The extra set of eyes is definitely welcomed.

          Best Regards,
          Jai

          Comment

          • prashanth023
            New Member
            • Apr 2007
            • 13

            #6
            Hi,
            You are using firstname,lastn ame,email filed names in the form.

            but you are accesing with another name i.e.$_POST[sender_name] ,$_POST[sender_email]. This will not work.

            Use same name. i.e. $_POST[firstname] ,$_POST[email ]

            Comment

            • jaiwilliams
              New Member
              • Apr 2007
              • 5

              #7
              Originally posted by prashanth023
              Hi,
              You are using firstname,lastn ame,email filed names in the form.

              but you are accesing with another name i.e.$_POST[sender_name] ,$_POST[sender_email]. This will not work.

              Use same name. i.e. $_POST[firstname] ,$_POST[email ]
              Hey,

              I tried this last suggestion from you and it worked! Thanks SO much for the advice. Seems like that would've been an obvious thing to check. Right in front of my face, and I couldn't see it. Thanks again.

              Jai

              Comment

              Working...