Search code examples
phphtmlemailphpmailerphp-include

Send an email with a variable defined in another file


I have file html like example.php

Url <a href="<? echo $var ?>"><? echo $var ?></a>

and i want send mail with this file with variable defined in send.php

<?php
$var = "someurl";
$contents = file_get_contents("example.php");
mail("[email protected]", "x", $contents");
?>

And my problem is this that send.php send Url <a href="<? echo $var ?>"><? echo $var ?></a> instead

Url someurl

where someurl is hyperlink.

I tried with fread() but the effect is the same.

Anyone have any ideas how to do it?


Solution

  • You can use Php's output buffering and an include:

    <?php
    $var = "someurl";
    ob_start();
    include 'example.php';
    $contents = ob_get_clean();
    mail("[email protected]", "x", $contents);
    ?>