<?php
if (isset($_POST['submit'])) {
    $secret = '6Ld_YSQqAAAAALnnAUnnmIDzTgVKxG3Z-Zhv3Cbs';
    $response = $_POST['g-recaptcha-response'];
    $remoteip = $_SERVER['REMOTE_ADDR'];
    $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip";
    $data = file_get_contents($url);
    $row = json_decode($data, true);

    if ($row['success'] == true) {
        $Name = $_POST['con_name'];
        $Emailid = $_POST['con_email'];
        $Phone = $_POST['con_phone'];
        $con_message = $_POST['con_message'];
        $to = 'info@jsfl.in';
        $subject = "JSFL : Contacts";
        $message = "Name: $Name\n\nEmailid : $Emailid\n\nPhone : $Phone\n\nMessage : $con_message";
        $from = "From:$Emailid" . "\r\n";
        $sent = mail($to, $subject, $message, $from);

        if ($sent) {
            header("Location: thanks.html");
            exit;
        } else {
            print "We encountered an error sending your mail";
        }
    } else {
        echo "<script>alert('Oops you are a robot');</script>";
        header("Location: CONTACTS.php");
        exit;
    }
}
?>