Forum Moderators: coopster
Here's the scenario, previously how I did this was set the variable as follows
$htm = "some text for the email " . $variable . " some text";
The $html variable was then used as the email body when it was sent out.
What I would like to know if there is an easy way to attach an external file to this variable so that I can set up external template files for the emails.
eg.
$html = some way to attach my external file to this variable;
external file would be something like
<table width="540" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td colspan="2">Below are the results of the New Member Survey submitted by: <strong><?php echo $first_name;?> <?php echo $last_name;?></strong></td>
</tr></table>
You can define a string with HTML by doing something like this:
$html = <<<html
<table width="540" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td colspan="2">Below are the results of the New Member Survey submitted by: <strong>$first_name $last_name</strong></td>
</tr></table>
html;
Basically you enclose all your HTML markup inside the <<<html and html; parts. Notice also that you don't have to use <?php echo $x;?> and can just call the strings because it's all parsed through PHP. Naturally, your variable doesn't have to be called $html, it can be called anything you like.
Anyway, I hope this is useful to you.
$html = implode('',file('server_path/to/file.txt'));
on edit:
What you would do in the template file (which doesn't have to have a txt extension as above) is 'embed' your variable information using the delimiters of your choice - I generally use the curly braces:
...New member...{first_name}...other text
then after you read the file into $html, use str_replace:
$html = str_replace('{first_name}',$first_name,$html);