simple PHP form question

Discussion in 'PHP' started by clouting, Jan 22, 2008.

  1. #1
    hi all,

    just need some quick help, i think it is simple.
    I have made a php form, it all works fine, however i need the main message to display several of the form elements.

    the code currently looks like this

    <?php 
    $to = "someone@hotmail.com";
    $from = $_REQUEST['Lname']; 
    $subject = $_REQUEST['Lname']; 
    $email = $_REQUEST['Fname'] ; 
    $message = $_REQUEST['what'] ; 
    $headers = "From: $email"; 
    $sent = mail($to, $subject, $message, $headers) ; 
    if($sent) 
    {print "Your mail was sent successfully"; }
    else 
    {print "We encountered an error sending your mail"; }
    ?> 
    PHP:
    however...........

    in the $message section i would like to have several elements included. eg. what, Fname, Lname. how do i code this.

    i assume it would be something like........
    $message = $_REQUEST['what', 'Fname', 'Lname'] ;
    PHP:
    but cant get it to work.

    any help would be appreciated.
     
    clouting, Jan 22, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $message = "{$_REQUEST['what']} some text or whatever {$_REQUEST['Fname']} etc.... la la la ... {$_REQUEST['Lname']}";
    
    PHP:
     
    nico_swd, Jan 22, 2008 IP
  3. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Alternately :
     $message = $_REQUEST['what'] ; 
    $message = "From:".$from."\n".$message ; 
    PHP:
    try that . .
    to add more varibles . .just follow the same format
    eg :
     
    $message = "From:".$from."Lastname:"$lname . $message ;
    PHP:
     
    killerj, Jan 22, 2008 IP
  4. clouting

    clouting Guest

    Messages:
    120
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks both of u. solved it.

    thanks for fast reply
     
    clouting, Jan 22, 2008 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Don't do this. Nothing should go in the headers unless you know it is clean.

    As it is now, people can use your form to send any spam message to any email address (or even to a thousand email addresses at a time), including virus attachments.

    In the very least, do something like this:

    
    $email = $_REQUEST['Fname'];
    $email = preg_replace('/[^\w@\.+\-]/', '', $email);
    $headers = "From: {$email}";
    
    PHP:
     
    SmallPotatoes, Jan 22, 2008 IP