How do you email form values in html?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • copleyuk
    New Member
    • May 2010
    • 39

    How do you email form values in html?

    I have created a form and am emailing it via php.

    If I use plain text I can get all the entered information to email correctly. However, I wanted to have the information from the form laid out in html so that I can make it look like a completed document staff would normally see instead of just a series of lines with text.

    I have tried a number of different combinations to get this to work but am getting nowhere fast!

    Here is what I have so far:

    Code:
    $deptname = $_POST['deptname'] ;
    $add1 = $_POST['add1'] ;
    etc
    
    $message = '
    
    <html>
    <body>
    
    Department Name: <?php $deptname ?>
    Address: <?php $add1 ?>
    etc
    
    mail($to, $message, $headers )
    
    </body>
    </html>
    ';

    I am receiving the email in HTML with the "Department Name:" part displayed but the user entered value is blank...


    I'm fairly new to both html and php and cannot seem to find how to get this working so that I can apply the layout and formatting!!

    Any help would be greatly appreciated!

    Thanks

    Carl
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I'm too tired to write an explanation, so just look at this example.

    Code:
    <?php
    
    // Ignore that I'm doing no sanity-checking here
    $name = $_POST['name'];
    $age  = $_POST['age'];
    
    $message = <<<MAIL
      Name: $name
      Age:  $age
    MAIL;
    
    // $to and $headers would have to be defined
    if ( mail($to, $message, $headers) )
      echo "Message sent successfully.";
    else
      echo "Message not sent successfully.";
    References:



    Comment

    • copleyuk
      New Member
      • May 2010
      • 39

      #3
      Thank you soooooo much Marcus!

      Thats working perfectly!
      I've been trying to figure that out for too long.

      Thanks again

      Carl

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        You're welcome.

        Comment

        Working...