Log in

View Full Version : print string stored in txt/htm file



jigneshsoni1981
05-30-2009, 06:52 AM
Hi All,

I am new to PHP and need help on below:

I have one text/html file that contains string to send emails to user, now that text/html file contains php variables also. i dont know how to replace those variables with actual values stored in a variables. For Ex.

txt file contains...
"Dear $username,
We have received your order..."

now when we do
echo $file_content

it displays $username instead of values

how to display actual value for this, please help on this.

Thanks in advance

forum_amnesiac
05-30-2009, 08:42 AM
It would be easier to answer this if we could see your code.

I'm assuming that your HTML file is collecting data from field inputs.

One of the ways to send an email using this data is to have a Form method, eg method="POST" and then an action that calls the PHP emailer.

In the PHP script you need to get the values of the various fields by $varname1=$_POST['fieldname1'];.

To then build up another variable that would be the emailed string, using the values of the PHP variables, you can concatenate by using the ".".

Eg $messageline1="Dear ".$varname1;
$messageline2="Thank you for your order no. ".$varname2;

Or $message = "Dear \t$varname1 \n
\nThank you for your order no. :\t$varname2\n
\n";

However if you want the email to look similar to an HTML input page, ie logos, layout, etc., then you need to use an emailer that enables this, there are a number of PHP HTML email scripts out there, some of which are surprisingly easy to use.

jigneshsoni1981
05-30-2009, 09:38 AM
Hey Thanks for the help,

my intension is to create mail templates only..

I have received all my FORM variables to PHP, now variables contain values.
I have read HTML template content by fread to a PHP variable $MailBody

now $MailBody contains string like

Dear $username,
We have received your order...

If you see above, $MailBody contains another PHP variable inside string,
and I want to replace that variables value with $username variable that i received from FORM method

Ex.

$username = $_POST['username']; // value is John

$MailBody = read_file("template.htm"); // Value is Dear $username

echo $MailBody;

// it prints dear $username instead of Dear John

forum_amnesiac
05-30-2009, 10:32 AM
You could always do this


$username = $_POST['username']; // value is John

$MailBody = read_file("template.htm"); // Value is Dear

echo $MailBody.$username;

The other thing you could try is to build the HTML string that you put into "template.htm" like this
var1='"Dear".$username'

and echo this