PHP的-file_get_contents()与字符串变量? [英] PHP - file_get_contents() with variable in string?

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

问题描述

我正在尝试在收到此订单时使用PHPMailer通过电子邮件将订单发送给客户. 我尝试过这种方式:

Im trying to email an order with PHPMailer to the customer when this order is received. I tried doing that this way:

        $email_page = file_get_contents("email_order_html.php?order=$order_id");

我想以字符串形式获取此页面的内容,以便可以使用PHPMailer发送此内容,但是由于其中包含变量$ order_id,此函数无法执行该页面,如何解决此问题?

I want to get the contents of this page as string so I can send this with PHPMailer but this function wont execute the page because of the variable $order_id in it, how can I fix this?

推荐答案

仅当将file_get_contents与URL感知流包装一起使用时,才能添加查询参数.它适用于http://localhost/yourfile.php?foo=bar.这样做会使用指定的查询参数向本地主机上的Web服务器发出HTTP Get请求.该请求将被处理,并返回请求的结果.

You can only add Query Params when using file_get_contents with an Url Aware Stream Wrapper, e.g. it would work for http://localhost/yourfile.php?foo=bar. Doing so would issue an HTTP Get Request to a webserver at localhost with the specified query params. The request would be processed and the result of the request would be returned.

仅将file_get_contents与文件名一起使用时,不会有任何HTTP请求.该呼叫将直接转到您的文件系统.您的文件系统不是Web服务器. PHP将仅读取文件内容.它不会执行PHP脚本,只会返回其中的文本.

When using file_get_contents with a filename only, there wont be any HTTP Requests. The call will go directly to your file system. Your file system is not a webserver. PHP will only read the file contents. It wont execute the PHP script and will only return the text in it.

您应该 include 并调用任何脚本手动执行.如果脚本取决于order参数,请在包含文件之前通过$_GET['order'] = $orderId进行设置.

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

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