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");
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?
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.
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.
You should include
the file and call whatever the script does manually. If the script depends on the order argument, set it via $_GET['order'] = $orderId
before including the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With