lets say i have a file named test.html and i want to store all the text of this file into a variable named $email.
how would i do that and be able to change few things in text with string replace command.

I am just trying to make html email template for my website so that i dont have to edit the code itself to change the way the email looks.
if you know of any other way i can make email template then tell me.

12 Years
Discussion Span
Last Post by ashneet

You can use Fread function to get the content of your webpage to $email variable. Then use str_replace function to replace any thing you want to change. If needed, you can also use explode function to split content into pieces.

good luck.


if I understand this correctly this code would store content of a file in a variable:

$info = fread(./email.html);

I am looking at the examples provided at php.net and they are comfusing me more then helping me because what i understand there is that I have to use fopen function first then use fread.
If any one can give me a better example that would be nice.


I also tried the fread meathod but everytime i do this i get a email with everything except what is in that template file. so another words i get a blank email. here is how my variable are set up:

$TO = 'ashneetgujral@aol.com';
$SUBJECT = "hello how are you doing";
$Header  = 'MIME-Version: 1.0' . "\r\n";
$Header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$MESSAGE = fread("./email/signup.html");
$MESSAGE = str_replace('*U_name*',$_POST['U_name'], $MESSAGE);

You have to fopen first before you can fread or fget.

$template = './email/signup.html';
$fd = fopen($template,"r");
$message = fread($fd, filesize($template));
// try output it on screen to validate the $message 
// before doing the mail function
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.