php - 带有查询字符串的 file_get_contents

标签 php email file-get-contents

我正在尝试从 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/

相关文章:

php - 在 Laravel 上更改密码重置的电子邮件 View 路径

email - return-path、reply-to 和 from 之间的行为差​​异是什么?

php - 将file_get_contents与错误的代理一起使用时,如何处理500个内部服务器错误?

php - PHP 脚本可以与 C 程序对话吗?

php - 迭代表列并获得结果

php - 为每个电子邮件 ID :Yii 生成一个唯一链接

curl - file_get_contents 和 curl 都不起作用

php - 如何在 URL 中使用带有非英文符号的 file_get_contents()?

php - 多个 mysql ORDER BY 用于多维排序/分组

javascript - 选择下拉列表时生成更多 MYSQL 数据库结果