<?php
function get_client_ip() {
    $ipaddress = '';
    if (getenv('HTTP_CLIENT_IP'))
        $ipaddress = getenv('HTTP_CLIENT_IP');
    else if(getenv('HTTP_X_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
    else if(getenv('HTTP_X_FORWARDED'))
        $ipaddress = getenv('HTTP_X_FORWARDED');
    else if(getenv('HTTP_FORWARDED_FOR'))
        $ipaddress = getenv('HTTP_FORWARDED_FOR');
    else if(getenv('HTTP_FORWARDED'))
       $ipaddress = getenv('HTTP_FORWARDED');
    else if(getenv('REMOTE_ADDR'))
        $ipaddress = getenv('REMOTE_ADDR');
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}
 $ip= get_client_ip();
 
include("phpmailer/class.phpmailer.php");
include("phpmailer/class.smtp.php");
include("phpmailer/class.pop3.php");

function clean($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

if (isset($_POST['enq_formBtn'])) {
    $user_name = clean($_POST['name']);
    $user_name = ucfirst(strtolower($user_name));
    $email = clean($_POST['email']);
    $contact = clean($_POST['phone']);
    if (isset($_POST['enq_loan'])) {
$enq_loan = clean($_POST['enq_loan']);
}
else{
    $enq_loan="No";
    
}
    $message = '
        <!DOCTYPE HTML>
        <html lang="en-US">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        </head>
        <body>
            <div id="email-wrap">
            <h1>Mountain View-S.P.Road Pune Details</h1>
            <br>
            <h4>
            You have received a new message from your website contact form.<br>Here are the details:
             </h4>
            <p>Project Name : Mountain View-S.P.Road Pune</p>
            <p> <b>Name :-</b> ' . $user_name . '<br></p>
            <p> <b>Email id :- </b>' . $email . '<br/></p>
            <p> <b>Mobile No :- </b>' . $contact . '<br/></p>
            <p> Message IP address :-'.$ip.'</p>
            <p> Needed Home Loan:-'.$enq_loan.'</p>
            </div>
        </body>
        </html>';

    $mail = new PHPMailer(); // create a new object 
    $mail->IsSMTP(); // enable SMTP 
    $mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only 
    $mail->SMTPAuth = true; // authentication enabled 
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail 
  $mail->Host = 'mail.mediawolf.in';
    $mail->Port = 465;
    $mail->Username = 'leads@mediawolf.in';
    $mail->Password = 'ySDV,Un#o+FC';
    $mail->addCustomHeader('MIME-Version: 1.0');
    $mail->addCustomHeader('Content-Type: text/html; charset=ISO-8859-1');
    $mail->SetFrom('info@nestrov.com');
    $mail->AddCC('mediawolfind@gmail.com ');
    $mail->Subject = 'Mountain View-S.P.Road Pune  Enquiry';
    $mail->isHTML(true);
    $mail->Body = $message;
    $mail->AddAddress('leads.deshpande@gmail.com');
    if (!$mail->Send()) {
        echo 'Mailer error: ' . $mail->ErrorInfo;
    }else {
       ?>
       <script> 
       alert("Thank you for your enquiry we will get back to you asap");
       window.location="index.php";
       </script>
       <?php
    }
    
        $name = $user_name ;
        $mobile = $contact;
        $email = $email;
        $bhk_unit = "3 and 4 BHK";
        $project = "Kolte Patil 24K altura";
        $api_key = "Nestrov Web Leads";
        $owner_id = "2";
        $location = " Baner";

        $postdata=array("name"=>$name, "mobile"=>$mobile, "email"=>$email, "bhk_unit"=>$bhk_unit, "project"=>$project);  

        $urldata=array("api_key"=>$api_key,"location"=>$location,"owner_id"=>$owner_id);

        $result = httpGet($urldata,$postdata);
    
  
  
           
}

  function httpGet($urldata, $data)
    {
    $baseurl="https://app.nestrov.com/api/Integration/postresponse.php"; 
    $url = $baseurl."?".http_build_query($urldata)."&". http_build_query($data); 
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_HTTPGET, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
    }
?>
