Custom Form Processing Issue

Instead of sending the form to a custom PHP script where you must load WordPress manually, you should send the from directly to a WordPress page.

You could use admin_post_{action} hook, it is similar to how admin-ajax.php works, but used to handle GET and POST requests.

The form:

<form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post">
  <input type="hidden" name="action" value="my_action">
  <input type="submit" value="Submit">
</form>

And the actions:

add_action( 'admin_post_my_action', 'cyb_my_action' );
add_action( 'admin_post_nopriv_my_action', 'cyb_my_action' );
function cyb_my_action() {
   // Process your form here
}

You could also send the form to any other page within WordPress and process the form in init action hook (or any other action you may consider better for your needs, but init is, general, a good action to proccess custom forms).

For example, if the form is embeded in a post of any type, including pages, you could send the form to itself:

<form id="cyb-contact-form" action="<?php echo esc_url(get_the_permalink()); ?>" method="post">
</form>

Them, you can process it on init action hook:

add_action( 'init', 'cyb_process_my_form' );
function cyb_process_my_form() {
   // Process your form here
}