Read HTML file into email
Posted
by cast01
on Stack Overflow
See other posts from Stack Overflow
or by cast01
Published on 2010-04-06T12:33:54Z
Indexed on
2010/04/06
16:03 UTC
Read the original article
Hit count: 348
Ive written a script to send html emails and all works well. I have the email stored in a separate HTML file which is then read in usin a while loop and fgets(). However, i want to be able to pass variables into the html. For example, in a html file i may have something like..
<body>
Dear Name <br/>
Thank you for your recent purhcase
</body>
and i read this into a string like so
$file = fopen($filename, "r");
while(!feof($file)) {
$html.= fgets($file, 4096);
}
fclose ($file);
I want to be able to replace "Name" in the html file by a variable and im not entirely sure on the best way to do this. I could always make my own tag and then use regex to replace that with the name once ive read the file into the string, but im wondering if there is a better/easier method to do this.
(On a side note, if anyone knows whether its better to use file_get_contents instead of multiple calls to fgets, id be interested to know)
© Stack Overflow or respective owner