<?php
error_reporting(0);
ini_set('display_errors','off');

$filename="admin/settings/personal_settings.txt";
		
if($handle = @fopen($filename, 'r')) 
{
$contents = fread($handle, filesize($filename));
fclose($handle);
$personal_arr=explode("#_1_#",$contents);
}
?>
<?php
if($personal_arr['5']==1)
{
?>
<?php
//Captcha Start
    if ($_SERVER["REQUEST_METHOD"] == "POST") {

        // access
        $secretKey = "$personal_arr[7]";
        $captcha = $_POST['g-recaptcha-response'];

        if(!$captcha){
          echo '<p style="font-size:18px; color:#FF0000; font-weight:bold">Please check the the captcha form.</p>';
          exit;
        }
        # FIX: Replace this email with recipient email
        $mail_to = "$personal_arr[1]";
        
        # Sender Data
        $name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
        $contact = filter_var(trim($_POST["contact"]), FILTER_SANITIZE_EMAIL);
        $notes = trim($_POST["notes"]);
        
        if ( empty($name) OR !filter_var($contact, FILTER_VALIDATE_EMAIL) OR empty($notes)) {
            # Set a 400 (bad request) response code and exit.
            http_response_code(400);
            echo '<p style="font-size:18px; color:#FF0000; font-weight:bold">Please complete the form and try again.</p>';
            exit;
        }

        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);

        if(intval($responseKeys["success"]) !== 1) {
          echo '<p style="font-size:18px; color:#FF0000; font-weight:bold">Please check the the captcha form.</p>';
		  
        } else {
            # Mail Content
$name = $_POST['name']; 
$contact = $_POST['contact']; 
$notes = $_POST['notes'];

		   
$notes = stripslashes($notes);
$name = "$name";
$contact = "$contact";
$from = "From: $contact"; 

$subject = "Website Email Contact";

$message = "
Name: $name
Message: $notes
";

$success = mail($mail_to, $subject,  $message, $from);
            if ($success) {
                # Set a 200 (okay) response code.
                http_response_code(200);
                echo '<p style="font-size:18px; color:#339900; font-weight:bold">Thank You! Your message has been sent.</p>';
            } else {
                # Set a 500 (internal server error) response code.
                http_response_code(500);
                echo '<p style="font-size:18px; color:#FF0000; font-weight:bold">Oops! Something went wrong, we couldnt send your message.</p>';
            }
        }

    } else {
        # Not a POST request, set a 403 (forbidden) response code.
        http_response_code(403);
        echo '<p style="font-size:18px; color:#FF0000; font-weight:bold">There was a problem with your submission, please try again.</p>';
    }
?>
<?php
} else {
//nocaptcha
$mail_to = "$personal_arr[1]";
$name = $_POST['name']; 
$contact = $_POST['contact']; 
$notes = $_POST['notes'];

		   
$notes = stripslashes($notes);
$name = "$name";
$contact = "$contact";
$from = "From: $contact"; 

$subject = "Website Email Contact";

$message = "
Name: $name
Message: $notes
";

$success = mail($mail_to, $subject,  $message, $from);
            if ($success) {
                # Set a 200 (okay) response code.
                http_response_code(200);
                echo '<p style="font-size:18px; color:#339900; font-weight:bold">Thank You! Your message has been sent.</p>';
            } else {
                # Set a 500 (internal server error) response code.
                http_response_code(500);
                echo '<p style="font-size:18px; color:#FF0000; font-weight:bold">Oops! Something went wrong, we couldnt send your message.</p>';
            }
//nocaptcha
}
?>