9

I have PHP file for make table with data row from database . I want send this page to email . but when I get content contains HTML and PHP code . but I want send only result of page in HTML.

i use this code

    $str =  file_get_contents( 'template.php' );
    $mail = "[email protected]";
    mail($mail,$str);

and this

$str = readfile("'template.php'");

but result contains php code in email . how i can get only html result?

1
  • Why do you use '/path/to/template.php' instead of /path/to/template.php? Skip the apostrophes! You can get the content of a PHP file by using output buffers and one of the include/require functions. Commented Mar 17, 2014 at 6:54

2 Answers 2

21
function getRenderedHTML($path)
{
    ob_start();
    include($path);
    $var=ob_get_contents(); 
    ob_end_clean();
    return $var;
}

This function will do what you want.

Sign up to request clarification or add additional context in comments.

2 Comments

return ob_get_clean();.
Cannot redeclare connect() (previously declared) . i used connect in template page and need to add in this page too . with this function return error
0

file_get_contents simply returns file contents, while you need to execute script and take it's output.

See this: https://stackoverflow.com/a/171327/421752

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.