Php file that doesn’t recognize wordpress functions

It doesn’t recognize WP, because as far as PHP is concerned it’s not. It’s just a PHP file that happens to be in one of the folders related to WordPress.

You need to explicitly include WordPress core into it to have access to its functionality. However such custom handlers are notoriously fragile.

It would be much more reliable to create endpoint by means of WordPress functionality. See Rewrite API and around in Codex.