Newbie: help with mail script

Discussion in 'PHP' started by adamjthompson, Jan 19, 2006.

  1. #1
    Hi,

    I have the following script, which works great:

    <?php
    // The message
    $message = "Catalog Request\nLine2here\nLine3here";
    
    // In case any of our lines are larger than 70 characters, we should use wordwrap()
    $message = wordwrap($message, 70);
    
    // Send
    mail('adamjthompson@earthlink.net', 'Catalog Request', $message);
    ?> 
    
    Code (markup):
    Here's what I can't figure out how to do. I'm going to have a form submitting (POST) to this script. I want to take the form input and put it into the email message.

    I tried using this in place of the line 2 above, but it didn't work:
    echo $_POST["firstname"];
    Code (markup):
    How should I do this?

    Thanks!

    Adam
     
    adamjthompson, Jan 19, 2006 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    to echo a var simply escape the echo

    echo "Hello ".$name." How are you?";

    so in the echo use ". to start the var and ." to end.
     
    onlyican.com, Jan 19, 2006 IP
    adamjthompson likes this.
  3. adamjthompson

    adamjthompson Well-Known Member

    Messages:
    1,242
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Thank you! I ended up with the following, which works great!

    <?php
    // The message
    $message = "Catalog Request\n".$_POST["firstname"]."\n".$_POST["lastname"]."\n".$_POST["address"]."\n".$_POST["city"]."\n".$_POST["state"]."\n".$_POST["zip"]."\n".$_POST["phone"]."\n".$_POST["email"]."";
    
    // In case any of our lines are larger than 70 characters, we should use wordwrap()
    $message = wordwrap($message, 70);
    
    // Send
    mail('adamjthompson@earthlink.net', 'Catalog Request', $message);
    ?>
    
    <html>
    <head>
    <title>Thank You</title>
    </head>
    <body>
    Thank You!
    </body> 
    </html>
    Code (markup):
     
    adamjthompson, Jan 19, 2006 IP