I am writing an email module for my web application that sends an html email to a user when a task is completed, such as registering. Now that the formatting of this letter may change, I decided to create an html page template, which is an email address, with custom tags in it that need to be replaced, for example,% fullname%.
My function has an array in array format (% fullname% => 'Joe Bloggs'); with the key as the tag identifier and the value that it needs to be replaced.
I tried the following:
$fp = @fopen('email.html', 'r'); if($fp) { while(!feof($fp)){ $line = fgets($fp); foreach($data as $value){ echo $value; $repstr = str_replace(key($data), $value, $line); } $content .= $repstr; } fclose($fp); }
Is this the best way to do this? since only 1 tag is being replaced at the moment ... am i on the right path or miles from ??
thanks...
source share