PHP:通过电子邮件发送 PHP 模板文件的 HTML 正文

发布于 2024-08-04 19:16:13 字数 224 浏览 2 评论 0原文

我目前正在使用 PHP 的 mail() 函数通过连接通过电子邮件发送另一个 PHP 文件的 HTML 正文。

目前这工作正常,但是,我更喜欢脚本简单地获取解析的 HTML Body,而不是使用串联方法。

我读过一些关于使用 fopen() 和 fread() 的不完整的论坛帖子,但我自己却没有运气。 我必须工作的任何输出都没有解析文件中的 PHP。

有没有可用的功能可以做到这一点?

I'm currently using PHP's mail() function to email the HTML Body of another PHP file using concatenation.

This is currently working fine, however, I would prefer the script to simply get the parsed HTML Body rather than using the concatenation method.

I've read a few incomplete forum posts regarding using fopen() and fread() but had no luck myself.
Any output I have got to work has not parsed the PHP within the file.

Is there a function available that can do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2024-08-11 19:16:13

你可以这样做:

ob_start();
require 'some_script.php';
$html = ob_get_clean();

然后你就得到了脚本的输出。

如果需要调用 URL,可以使用 cURL 来执行此操作,或者如果在 PHP 设置中启用了该选项,则可以将 fopen()/fread() 与 URL 结合使用。我认为该选项称为allow_url_fopen 或类似的名称。

$handle = fopen("http://www.example.com/", "r");
$output = fread($bundle, 20000);

You can do:

ob_start();
require 'some_script.php';
$html = ob_get_clean();

and then you have the output of the script.

If you need to call a URL, you can do this with cURL or alternatively you can use fopen()/fread() with a URL if that option is enabled in your PHP setup. I think the option is called allow_url_fopen or something similar.

$handle = fopen("http://www.example.com/", "r");
$output = fread($bundle, 20000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文