How do I format captured form data into a table to send in email

Posted on 2009-04-29
Last Modified: 2013-12-13
The code below is from the processing script for a form.  I want to format the captured data as a 2 column table - [fieldname] [value] in the email that is sent.  
//Sending Email to form owner

$pfw_header = "From:\n"

  . "Reply-To:\n";

$pfw_subject = "Admin Email with All Fields data - $medSpecialties";

$pfw_email_to = "";

$pfw_message = "medSpecialties:   $medSpecialties\n"

. "surgSpecialties:   $surgSpecialties\n"

. "Patient Name:   $patName\n"

. "Date of Birth:   $patDOB\n"

. "Parent/Guardian:   $parent2\n"

. "Preferred Phone 1:   $prePhone1\n"

. "Preferred Phone 2:   $prefPhone\n"

. "DCF:   $dcf\n"

. "Social Worker Name: $socialWkrName\n"

. "Social Worker Phone: $socialWkrPhone2\n"

. "Residential Placement: $resPlacement\n"

. "Residential Placement Address: $resAddress\n"

. "Residential Placement Phone: $resPhone\n"

. "Completed On-line Appointment Request: $onlineAppt\n"

. "Household Language Preference (other than English): $houseLang\n"

. "Household Language Preference: $houseLangOther2\n"

. "Translation Services Needed: $translationSvcs\n"

. "Hearing Impaired Services Needed: $hearingSvcs\n"

. "Referring Provider Name: $refProviderName2\n"

. "Referring Provider Phone: $refProviderPhone2\n"

. "Referring Provider Fax: $refProviderFax2\n"

. "Referring Provider Email: $refProviderEmail2\n"

. "Other Pediatric Specialist Name1: $MDName1\n"

. "Other Pediatric Specialist Specialty1: $MDSpecialty1\n"

. "Other Pediatric Specialist Name2: $MDName2\n"

. "Other Pediatric Specialist Specialty2: $MDSpecialty2\n"

. "Other Pediatric Specialist Name3: $MDName3\n"

. "Other Pediatric Specialist Specialty3: $MDSpecialty3\n"

. "Reason for Referral: $refReason2\n"

. "Is Family Aware of Referral Reason: $famAware\n"

. "Provider Call Requested: $providerCall\n"

. "Initiate Co-management Protocol (if available): $coMgmtProtocol\n"

. "Patient Name: $patName3\n"

. "Date of Birth: $patDOB3\n"

. "Sex: $patSex2\n"

. "Home Phone: $patPhone2\n"

. "Cell Phone: $patCell2\n"

. "Work Phone: $patWorkPhone2\n"

. "Address: $patAddress2\n"

. "PO Box: $patPOBox\n"

. "City: $patCity2\n"

. "State: $patState2\n"

. "Zip: $patZip2\n"

. "Guarantor: $guarantor\n"

. "Primary Language (if other than English): $patLanguage\n"

. "Insurance Primary: $insPrimary\n"

. "Primary ID Number: $insPrimaryID\n"

. "Specialist Co-Pay: $patPrimaryCopay\n"

. "Insurance Secondary: $patInsSecondary\n"

. "Secondary ID Number: $patIDNumSecondary\n"

. "Specialist Co-Pay: $patSecondaryCopay\n"

. "TodaysDate: $TodaysDate\n";

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

Open in new window

Question by:kimberlys777
    LVL 5

    Expert Comment

    The easiest way to accomplish this is probably to send the email as HTML, and then generate an HTML table. To send the email as HTML, simply change your $pfw_header to the following.


    $pfw_header = "From:\n"
      . "Reply-To:\n"
      . "MIME-Version: 1.0\n"
      . "Content-type: text/html; charset=iso-8859-1");

    Open in new window

    LVL 5

    Expert Comment

    The closing parenthesis obviously shouldn't be there. Sorry about that.
    $pfw_header = "From:\n"
      . "Reply-To:\n"
      . "MIME-Version: 1.0\n"
      . "Content-type: text/html; charset=iso-8859-1";

    Open in new window


    Author Comment

    Thanks.  I'm a little closer now.  I no longer get an error (whew!)  It sends the email but now it's one long line of text with no formatting.  Can you tell me how to format it into a table?
    LVL 5

    Accepted Solution

    Of course. The idea is to build your email just as if it's a web page. This will generate a table with two rows for the first two fieldnames and their values.
    $pfw_message = "<html><body><table border=\"0\">"
      . "<tr><td>medSpecialties:</td><td>$medSpecialties</td></tr>"
      . "<tr><td>surgSpecialties:</td><td>$surgSpecialties</td></tr>"
      . "</table></body></html>";

    Open in new window


    Author Comment

    FANTASTIC!!! It works!  Thank you so much.  Now I'm going to open a new question to try to get the results to print out on the confirmation page.  once again... THANK YOU!!!

    Author Closing Comment

    AtanAsfaloth - I can't thank you enough.  I'd been trying to figure this out for 2 days.  Your quick, polite and easy-to-understand solutions are greatly appreciated.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Easy Project Management (No User Manual Required)

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now