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 = "test@tst.com";
    mail($mail,$str);

and this

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

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

Grant
  • 2,413
  • 2
  • 30
  • 41
bnnoor
  • 656
  • 2
  • 13
  • 31
  • 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. – h2ooooooo Mar 17 '14 at 06:54

2 Answers2

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

This function will do what you want.

schnawel007
  • 3,982
  • 3
  • 19
  • 27
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

Community
  • 1
  • 1
Im0rtality
  • 3,463
  • 3
  • 31
  • 41