发送一封包含在另一个文件中定义的变量的电子邮件


Send an email with a variable defined in another file

我有类似example.php的html文件

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

我想用这个文件发送邮件,这个文件中定义了send.php中的变量

<?php
$var = "someurl";
$contents = file_get_contents("example.php");
mail("x@x.com", "x", $contents");
?>

我的问题是send.php发送Url <a href="<? echo $var ?>"><? echo $var ?></a>而是

Url someurl

其中someurl是超链接。

我试过用fread(),但效果是一样的。

有人知道怎么做吗?

您可以使用Php的输出缓冲和include:

<?php
$var = "someurl";
ob_start();
include 'example.php';
$contents = ob_get_clean();
mail("x@x.com", "x", $contents);
?>