Category: Client & Server Side Scripting (PHP, ASP, JavaScript)
Building an HTML Email with LOTS of vars: HTML, CSS, JavaScript, PHP
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.
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!
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
extract($_POST);
$output = "Field value is: $fieldname other info here";