PHP mail form - content string not working :(

Discussion in 'PHP' started by april, Mar 1, 2006.

  1. #1
    hi.

    using php, and more than 5 variables, i am trying to email a form when submitted on a website. i read on another forum the best way to do this is concatenate the content and pass in mail() as one variable. however, when i use the following code, i only get partial results... see below.

    ////////////
    //my code:
    ////////////

    <?php

    $to="test@test.com";
    $from="my_website";

    $company = $_REQUEST['company'] ;
    $name = $_REQUEST['name'] ;
    $phone = $_REQUEST['phone'] ;
    $email = $_REQUEST['email'] ;

    $content = "Company: " . $_REQUEST["company"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Name: " . $_REQUEST["name"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Address 1: " . $_REQUEST["address"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Address 2: " . $_REQUEST["address2"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Phone: " . $_REQUEST["phone"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Email: " . $_REQUEST["email"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Fax: " . $_REQUEST["fax"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Message:\r\n" . $_REQUEST["message"] . "\r\n";
    $content .= "------------------------------------\r\n";

    if (empty($company) || empty($name) || empty($phone) || empty($email))
    {
    header( "Location: http://www.test.com/error.html" );
    }
    else
    {
    mail( $to, $from, "my emailed form", $content );
    header( "Location: http://www.test.com/thankyou.html" );
    }
    ?>



    //////////////
    //my results:
    //////////////

    ------------------------------------
    Message:
    ehfsdjkfhsjkfhjskdhfdsjkhfjksdhfjsdhfjshkfhsjkfhjkshfkjshjkd
    ------------------------------------


    that's it. i only get the last piece of data requested. i dont know where the rest of my information went!! why is it not grabbing all of my content?

    PLEASE HELP!!

    april
     
    april, Mar 1, 2006 IP
  2. woodside

    woodside Peon

    Messages:
    182
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You are missing the "." on some of your lines where you use .=

    -Erik
     
    woodside, Mar 1, 2006 IP
  3. april

    april Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    awwwwwwwwwwww... shoot.

    i guess i was off with the ".=" on this part..

    $content = "Company: " . $_REQUEST["company"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Name: " . $_REQUEST["name"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Address 1: " . $_REQUEST["address"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Address 2: " . $_REQUEST["address2"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Phone: " . $_REQUEST["phone"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Email: " . $_REQUEST["email"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content = "Fax: " . $_REQUEST["fax"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Message:\r\n" . $_REQUEST["message"] . "\r\n";
    $content .= "------------------------------------\r\n";

    i changed it to the below and now it works...

    $content = "\r\n------------------------------------\r\n";
    $content .= "Company: " . $_REQUEST["company"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Name: " . $_REQUEST["name"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Address 1: " . $_REQUEST["address"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Address 2: " . $_REQUEST["address2"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Phone: " . $_REQUEST["phone"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Email: " . $_REQUEST["email"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Fax: " . $_REQUEST["fax"] . "\r\n";
    $content .= "------------------------------------\r\n";
    $content .= "Message:\r\n" . $_REQUEST["message"] . "\r\n";
    $content .= "------------------------------------\r\n";
     
    april, Mar 1, 2006 IP
  4. april

    april Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank You!!
     
    april, Mar 1, 2006 IP
  5. april

    april Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    also...

    how do i protect myself from email spammers??
     
    april, Mar 1, 2006 IP
  6. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #6
    tflight, Mar 1, 2006 IP
  7. tarun1979

    tarun1979 Peon

    Messages:
    198
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i think you need a little change in code

    if (conditions)
    {
    redirection to error page
    }
    else
    {
    initialise variables
    your "$content = " code
    mail function
    redirection to Thank u page
    }


    what do you say??
     
    tarun1979, Mar 2, 2006 IP
  8. advancescripts

    advancescripts Peon

    Messages:
    270
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    you can also use the image varification to stop the spammers
     
    advancescripts, Mar 3, 2006 IP