Google reCaptcha v2 Doesn’t Work using PHP on my Website

My website is a WordPress website. I wanted to create a form with a reCaptcha protection using Google reCaptcha v2 (tick box). Surprisingly it doesn’t work even though it works on my other website using same PHP code.

After Ticking the reCaptcha

google recaptcha v2 tick box
google recaptcha v2 tick box

It doesn’t work if use file_get_contents

Google reCaptcha keeps sending me error.

It works if using curl