PHP Help

Discussion in 'Web Design and Development' started by kaeckisthename, Feb 29, 2008.

  1. kaeckisthename macrumors member

    Joined:
    Aug 22, 2007
    #1
    I am designing a website for Grocery Pick Up and Delivery service. I created a form with all the necessary input areas (name, address, delivery time, etc.)

    I am trying to use PHP to collect the data of the form and email it to a specified email address.

    I have the message sending correctly, but it is a blank message that is sent.

    What I'm asking is......Is there a way to collect the ENTIRE FORM including all fields and email it. Or do I have to specify each individual field to collect

    here is the PHP I have...

    Code:
    <?php
       } else {
          error_reporting(0);
          $recipient = 'dkaeck@corsp.org';
          $subject = "Order Form";
          $from = stripslashes($_POST['Name']);
          $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
    	  $headers = "MIME-Version: 1.0\r\n";
          $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";$headers = "MIME-Version: 1.0\r\n";
          $headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
    	  $headers.= "From: $from\r\n";
          if (mail($recipient, $subject, $msg, $headers))
             echo nl2br("<b>Your Order Has Been Sent</b>
             To: $recipient
             Subject: $subject
             Message: Attached Order Form
             $msg");
          else
             echo "Your Order Failed To Send";
    }
    ?>
    I'm guessing that this part of the code is where the form or fields should be listed for submission.

    Code:
    $msg = "Message from: $from\n\n".stripslashes($_POST['MsgBody']);
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Yes you need to collect from each form field and make it part of the message that get emailed, none of that happens automatically. The form fields are accessed through the $_POST[] array and you access it by the form fields name attribute.
     
  3. kaeckisthename thread starter macrumors member

    Joined:
    Aug 22, 2007
    #3
    Okay, I kinda guessed that....I'm new to php and trying to learn a little bit

    Another Question...

    On this section here....
    Code:
    $msg = "Message from: $from\n\n".stripslashes($_POST['Name']).stripslashes($_POST['email']);
    How do I insert line breaks between the $_POST elements....I've tried the nl2br and \n but I get an error

    your help is very much appreiated
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    For readability I have often done,

    PHP:
    $msg "Message from: $from

    stripslashes(
    $_POST['Name'])\nstripslashes($_POST['email'])";
    Just typing in the new lines where needed since it'll read the string across lines in your PHP. Though the \n should also be working.
     
  5. kaeckisthename thread starter macrumors member

    Joined:
    Aug 22, 2007
    #5
    the values are still running as one line with no breaks on output
     
  6. notnek macrumors 6502

    notnek

    Joined:
    Oct 25, 2007
    #6
    I find it best & easiest to maintain if you post form data and assign them to variables, the perform the mail() function. Here's a sample...

     

Share This Page