Results 1 to 2 of 2

Thread: Building an HTML Email with LOTS of vars

  1. #1
    Join Date
    Jun 2005
    Posts
    2

    Building an HTML Email with LOTS of vars

    I am trying to build a HTML email that contains tables of data from a crazy long form. It was originally built in ASP as 2 pages, but our server is going to stop supporting ASP Very soon. therefore I am trying to re-write it in PHP...

    Here is an excerpt from the body var Im trying to build.
    PHP Code:
    $body ='<html><body bgcolor="#FFFFFF" text="#000000<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr bgcolor="#F5F0FF"><td colspan="6"><font face="Arial, Helvetica, sans-serifsize="3" color="#333399"><b>PERSONAL INFORMATION</b></font></td></tr><tr bgcolor="#F5F0FF"> <td width="22%">Last</td>    <td width="14%"> $field1 </td>'
    I am not sure how to insert this $field1 var without it coming out as flat text not the value. Usually I would use
    PHP Code:
    <?php $_POST['field1'?>
    right from the form it was submitted from but that wont work in an html tag like im trying to do. ANY Help would be greatful!

  2. #2
    Join Date
    May 2005
    Location
    Ohio
    Posts
    32
    A few things about working with post variables.

    To use $_POST['fieldname'] in a string, you have 3 options:
    1) nix the string quotes. The variable is still read when put in double quotes. Single quotes will not output the value like double quotes will.
    PHP Code:
    $output "Field value is: $_POST[fieldname]"
    2) drop out of the string to insert the value.
    PHP Code:
    $output "Field value is: ".$_POST['fieldname']." other info here"
    OR
    PHP Code:
    $output 'Field value is: '.$_POST['fieldname'].' other info here'
    3) One other way is to use the extract function. This basically takes the array key, fieldname, and creates a variable from it. This works on the whole array specified, so all $_POST items would be transferred as well.
    More info can be found at http://us2.php.net/manual/en/function.extract.php
    PHP Code:
    extract($_POST);
        
    $output "Field value is: $fieldname other info here"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •