PayPal uses HTTP 1.1 for IPN now. The sample scripts on X.com have been updated to reflect the changes. I would recommend trying to use one of the updated scripts.
The code you provided also responds to the Sandbox environment. If you aren't using the Sandbox that would cause the validation of the posts to fail.