我正在尝试从 php 发送电子邮件 我有一个包含所有值的 php 文件和其他 php 模板文件。
(两个文件在同一台服务器上)
例如,我正在使用 file_get_contents 获取 php 模板文件的内容
$url="emil_form.php";
$a="uname";
if(($Content = file_get_contents($url. "?uname=".$a)) === false) {
$Content = "";
}
...... EMAIL Sending Code ..........
这是 emil_form.php(电子邮件模板文件)的代码
Your Name is : <?php $_GET['uname']; ?>
所以一旦我在 $Content 中获得数据,我就可以通过电子邮件发送它。 但我收到无法打开文件的错误....
我想要的是将数据从原始 php 文件传递到模板 php 文件,并将模板的输出存储在变量中,以便我可以通过电子邮件发送它。
如何做到这一点?
谢谢
最佳答案
真正的问题是你试图读取一个本地文件,它后面有一个 http 查询字符串。文件系统不理解这一点并寻找名为“emil_form.php?uname=uname”的文件。 $_GET/$_POST/etc 仅适用于 http 连接。
尝试在您的模板中放置一个占位符,如“%%NAME%%”,并在阅读模板后替换它。
<?php
$url = "emil_form.php";
$a = "uname";
if(($Content = file_get_contents($url)) === false) {
$Content = "";
}
$Content = str_replace('%%NAME%%', $a, $Content);
// sending mail....
模板将如下所示:
Your Name is: %%NAME%%
关于php - 带有查询字符串的 file_get_contents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988707/