It is really difficult to debug IPN, but the most important thing is to make sure an IPN is being sent correctly.
In your PayPal account, under the Profile, there is a link to an IPN History page which lists all the Notifications to your site. Check that page and ensure there is an IPN that was made once the purchase was made and that that it was made to the correct url.
The second thing i recommend is that you simplify the page. Once you confirm there is an IPN, i recommend that you only send a Static email address to ensure IPN is working. And then you can go back and try to insert the order to the database.