Reputation: 149
I'm developing a PHP web app in which I need to send e-mails in HTML format.I'm using mail() function.
I want to send email based on a template file. This file is an html file in which I embed pieces of PHP code.
I'm having problem interpreting this template and outputting the result into a string variable that will be passed to mail() function.
function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
return ob_get_clean();
}
return false;
}
$mesaj_confirmare_cont = get_include_contents('../Anunturi-Lemn/signup/confirmation_email.html');
I use some variables in the caller script to be echoed in the template file, but they are not propagated in the included $filename. Why is that and how can I acomplish that?
Upvotes: 1
Views: 346
Reputation: 489
try to use
file_get_contents();
or
fread();
in some servers file_get_content
might be blocked so checkout you server configuration and use
Above step will give you content of file in a string
they you can use preg_replace
and or other string function to manipulate it
Upvotes: 0
Reputation: 1337
The variable needs to be passed into the function
function get_include_contents($filename, $my_first_var, $second_var) {
...
}
$mesaj_confirmare_cont = get_include_contents('...confirmation_email.html', $my_first_var, $second_var);
Upvotes: 1