View Full Version : Building an HTML Email with LOTS of vars

12 Aug 2005, 12:33 AM
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.

$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 $_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!

15 Aug 2005, 09:26 AM
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.
$output = "Field value is: $_POST[fieldname]";
2) drop out of the string to insert the value.
$output = "Field value is: ".$_POST['fieldname']." other info here";OR
$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
$output = "Field value is: $fieldname other info here";