Tom Tom -4 years ago 65
PHP Question

Passing file url with variables into Postmark causing file not found issue

So I'm using Postmark to send emails and the class I have requires a variable as the message body, as below:

$email->to(Input::post('email'))->subject("Verify Your Email Address")->html_message($html)->send();


This works fine if I set
$html
as just plain
html
.

What I am trying to do is send the contents of another php file from my site as this html.

I have tried:

$Vdata = file_get_contents('verification.php');


this works fine but as soon as I try and pass variables in it gives me an error:


file not found error


And sends a blank email, for example:

$Vdata = file_get_contents('verification.php?url=blah');


Essentially I just need
$html
to be the contents of
verification.php?url=blah
so that I can pass in variables to that file.

Can anyone help?

Answer Source

You're doing a local file inclusion, which means filenames ONLY. URLs are not permitted (query strings in particular) because you're NOT doing an HTTP request. PHP is going to look for a file whose name literally contains ?, u, r, etc... which of course doesn't exist.

If you want to use query strings, then you have to use a full-blown absolute URL, including the protocol:

include('http://....?url=...');

However, this is incredibly inefficient, and also highly dangerous. Since you're now EXECUTING the file specified in the url. you're going to get its output, not the raw PHP code in the file.

If you want to pass data to an included file, then just variables:

$foo = 'bar';
include('test.php');

and use look for/use those variables in the file.

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