twan twan - 1 year ago 67
PHP Question

Use posted data in a file that is included using file_get_contents

I am using an email template that is included using file_get_contents in my email script file.

The data from my contactform is posted to that email script. I would like to display the posted data inside the template layout. I can't echo the variables containing the posted data in the template file, so how would I do this?

file_get_contents only returns the text if I'm correct so it doesn't recognize variables right?

Answer Source

Actually you CAN turn the file you request with file_get_contents into a PHP file to echo your data. You need to use GET variables when you request the file with file_get_contents example:


After you do that, the requested PHP file gets executed on the server before it returns the result. so you can simply echo your data in the template at the desired place.

echo $_GET['name']; 

as @marc B commented: This will NOT work unless you use a full-blown url, causing an http request. your "url" will cause PHP to do a LOCAL fopen and look for a file which has the literal characters ?, n, a etc.. in the filename.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download