Try adding this to the top of your email-your-details.php page:
Since the email body page is included from the main page, the require_once() referencing the connection is ignored because it was already added before.
But since it is referenced from a function, the variables defined (the connection) is out of scope and can't be referenced.
Adding the global declaration will bring the variable back into scope. Another solution would be to change the require_once() around the connection reference to require(), but that is less efficient since it will open a new connection when one is already available from the original page.