file_get_contents与查询字符串 [英] file_get_contents with query string

查看:130
本文介绍了file_get_contents与查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从php
发送电子邮件我有一个php文件与所有值&其他php模板文件。

i am trying to send email from php i have one php file with all values & other php template file.

(这两个文件都在同一台服务器上)

(both files are on same server)

我正在使用file_get_contents获取php模板文件的内容例如

i am using file_get_contents to get contents of php template file for example

   $url="emil_form.php";
   $a="uname";
  if(($Content = file_get_contents($url. "?uname=".$a)) === false) {
   $Content = "";
    }

   ...... EMAIL Sending Code ..........

,这里是emil_form.php(电子邮件模板文件)的代码

and here is code for emil_form.php (email template file)

    Your Name is : <?php $_GET['uname']; ?>

所以一旦我在$ Content中获取数据,我可以通过电子邮件发送。
但是我收到错误无法打开文件....

so once i got data in $Content i can send it by email. but i am getting error unable to open file....

我想要的是将数据从原始php文件传递到模板php文件,什么将输出的模板存储在变量中,以便我可以通过电子邮件发送。

what i want is pass data from original php file to template php file and what will be output of template stored in variable so i can send it by email.

如何做?

谢谢

推荐答案

真正的问题是您尝试使用后面的http查询字符串读取本地文件。文件系统不明白这一点,并查找一个名为emil_form.php?uname = uname的文件。
$ _GET / $ _POST / etc仅适用于http连接。

The real problem would be that you try to read a local file with a http query string behind it. The file system don't understand this and looks for a file called "emil_form.php?uname=uname". $_GET / $_POST / etc only works over a http connection.

尝试在模板中放置%% NAME %%等占位符,阅读模板后,请将其替换。

Try to put a placeholder like "%%NAME%%" in your template and replace this after reading the template.

<?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%%

这篇关于file_get_contents与查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆