<?php

    if ($_SERVER["REQUEST_METHOD"] == "POST") {

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

        if(!$captcha){
        echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
         exit;
        }

	   
	   
	   
	   
	 //  date_default_timezone_set('Etc/UTC');
require_once 'phpmailer/PHPMailerAutoload.php';

//require_once 'phpmailer/class.phpmailer.php';


$mail = new PHPMailer();

$mail->isSMTP();

$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->Host = "mail.srvrone.com";
//$mail->Host = '172.24.17.25';


//$mail->Port = 443;
$mail->Port = 465;

$mail->SMTPSecure = 'tsl';
$mail->SMTPAuth = false;    
$mail->Username = 'webmaster@srvrone.com'; 

$mail->Password = 'WEBmaster@2022'; 

$mail->setFrom('webmaster@srvrone.com', 'Webmaster');
//$mail->setFrom('cms@designbox.com.kw', 'cms');


$mail->addAddress('info@sarangitech.com', 'complain');
//$mail->addAddress('viju@designbox.com.kw', 'viju');
//$mail->addCC('cms@designbox.com.kw','cms');
//$mail->addAddress('cms@designbox.com.kw', 'cms');
$mail->IsHTML(true); 

$mail->Subject  = 'this is test';
$mail->Body     = 'Email from Almanar';

	   

	   
	   
        # FIX: Replace this email with recipient email
        $mail_to = "info@sarangitech.com";

        
        # Sender Data
        $subject = trim($_POST["subject"]);
        $name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
        $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
        $phone = trim($_POST["phone"]);
        $message = trim($_POST["message"]);
        
        if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($phone) OR empty($subject) OR empty($message)) {
            # Set a 400 (bad request) response code and exit.
            http_response_code(400);
            echo '<p class="alert alert-warning">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 class="alert alert-warning">Please check the the captcha form.</p>';
        }
		else {
            # Mail Content
            $content = "Name: $name\n";
            $content .= "Email: $email\n\n";
            $content .= "Phone: $phone\n";
            $content .= "Message:\n$message\n";

            # email headers.
            $headers = "From: $name <$email>";

            # Send the email.
            $success = mail($mail_to, $subject, $content, $headers);
            if ($success) {
                # Set a 200 (okay) response code.
                http_response_code(200);
                echo '<p class="alert alert-success">Thank You! Your message has been sent.</p>';
            } else {
                # Set a 500 (internal server error) response code.
                http_response_code(500);
                echo '<p class="alert alert-warning">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 class="alert alert-warning">There was a problem with your submission, please try again.</p>';
    }

?>
