Advanced Search

Results 1 to 7 of 7

Thread: PHP Form-to-Email won't post input into email

  1. #1
    Join Date
    Jun 2009
    Location
    United States
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default PHP Form-to-Email won't post input into email

    Hi,

    I am working on a page where you fill out a form to sign up for an email newsletter. Sending an email alone is no problem, but the text entered into the form does not show up when I run a test.
    I know it probably has to do with how the info is being posted, but I haven't the slightest clue what code is missing/incorrect.
    All I'm trying to do is have the information entered into the form be in the body of the email the PHP sends out.

    Here's the form page: http://www.laurendragon.com/mailinglistform.php
    The code I'm using:
    PHP Code:
    <?php
    $ipi 
    getenv("REMOTE_ADDR");
    $httprefi getenv ("HTTP_REFERER");
    $httpagenti getenv ("HTTP_USER_AGENT");

    ?>

    <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
    <form method="POST" action="sendemail.PHP" name="mailinglist" id="mailinglist">
      <div align="left"> 
        <p align="center"><br>
          Name (First & Last):<br>
          <input type="text" name="Name"/>
          <br>
          <br>
          City:<br>
          <input type="text" name="City" />
          <br>
          <br>
          State:<br>
          <input type="text" name="State"/>
          <br>
          <br>
          Email:<br>
          <input type="text" name="Email"/>
      <br>
          <br>
    <input type="submit" VALUE="Sign Me Up" onClick="alert('Thank you! Your form has been sent.')" />
          <br>
        </p>
        </div>
    </form> 
    </form>
    Here is the sendemail.php code:
    PHP Code:
    <?php
    $to
    ="Laurendragon@laurendragon.net";
    $subject="Mailing List Signup";
    $body="
    Name 
    $name
    City 
    $city
    State 
    $state
    Email 
    $email";
    mail($to,$subject,$body);
    ?>
    I tried to change the code to a post array:
    PHP Code:
    $body="
    Name  
    $_POST['name']
    City  
    $_POST['city']
    State  
    $_POST['state']
    Email  
    $_POST['email']"
    I got this error message:
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in sendemail.php on line 15

    Line 15 when I look at it in Dreamweaver MX is Name $_POST['name']

    Any help is much appreciated.
    -Raven
    Last edited by Snookerman; 06-12-2009 at 04:04 PM.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try:

    Code:
    $body = "Name: ".$_POST['name']."\r\n";
    $body .= "City: ".$_POST['city']."\r\n";
    
    //rest of code here!
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    rsrwebs (06-11-2009)

  4. #3
    Join Date
    Jun 2009
    Location
    United States
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Well, I'm back to the drawing board again. The email sends fine, but the info entered in the form is not sent. This is all I see:

    Name:
    City:
    State:
    Email:


    Thanks for the response, though.

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

    Default

    Maybe try this and let us know your out puts

    PHP Code:
    $Name =  $_POST['Name'];
    $City $_POST['City'];
    $State $_POST['State'];
    $Email $_POST['Email'];  

    echo 
    "Your variables are set as:\n Name:" $name "\nCity:" $city ":\nState:" . $ state "\nEmail:" $email ;


    $body "Name:" $name "\nCity:" $city ":\nState:" . $ state "\nEmail:" $email ;

    if (empty(
    $body) || ($body=="") || (!isset($body)) {
    echo 
    "Body is empty";
    } else {
    echo 
    "You should have this in your email" $body;

    It may be that the post is case sensitive.

  6. The Following User Says Thank You to bluewalrus For This Useful Post:

    rsrwebs (06-12-2009)

  7. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by bluewalrus View Post
    It may be that the post is case sensitive.
    Yes, all variables are case sensitive so if you have a form named "name" but you are calling it in your PHP like so: $_POST['Name'], you will continue to get blank results.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. The Following User Says Thank You to thetestingsite For This Useful Post:

    rsrwebs (06-12-2009)

  9. #6
    Join Date
    Jun 2009
    Location
    United States
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default


    Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in D:\Hosting\4213630\html\sendemail.php on line 19


    That's what I got when I tried that, line 19 is echo "Your variables are set as:\n Name:" . $name . "\nCity:" . $city . ":\nState:" . $ state . "\nEmail:" . $email ;

  10. #7
    Join Date
    Jun 2009
    Location
    United States
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Yes, all variables are case sensitive so if you have a form named "name" but you are calling it in your PHP like so: $_POST['Name'], you will continue to get blank results.

    Hope this helps.
    Oh god thank you, wow... Words cannot describe how happy I am right now. :lol:
    I can't believe it was something so simple! Man I feel silly, oh well thank you guys!!!

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
  •