<?php
if(isset($_POST['submit'])){
    $name = $_POST['name'];
    $mobile = $_POST['mobile'];
    $email = $_POST['email'];
    $project = $_POST['af2'];
    
    function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
        $output = NULL;
        if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
            $ip = getenv("REMOTE_ADDR");
            if ($deep_detect) {
                if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
                    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
                if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
                    $ip = $_SERVER['HTTP_CLIENT_IP'];
            }
        }
        $purpose    = str_replace(array("name", "\n", "\t", " ", "-", "_"), '', strtolower(trim($purpose)));
        $support    = array("ipaddress");
        if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
            $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
            if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
                switch ($purpose) {
                    case "country":
                        $output = @$ipdat->geoplugin_countryName;
                        break;
                    case "countrycode":
                        $country_code = @$ipdat->geoplugin_countryCode;
                        $output = $countryarray[$country_code]['code'];
                        break;
                    case "ipaddress":
                        $output = $ip;
                }
            }
        }
        return $output;
    }
    
    $ip = $_POST['af4'] = ip_info("Visitor", "ipaddress");

    //email
    $to = "info@gatewaypropmart.com";
    $subject = "Enquiry From " . $project;

    $htmlContent = '<html>
    <body>
    <div style="background:#eceff0; padding:30px; font-family:Verdana, Geneva, sans-serif; font-size:13px;">
    <div style="background:#fff; border:1px solid#ccc; padding:25px;">

    <br><br>
    You have received a new enquiry from <strong>'.$project.'</strong> <br><br>
    Details are:<br><br>
    Name: '.$name.'<br>
    Mobile: '.$mobile.'<br>
    Email: '.$email.'<br>
    IP: '.$ip.'<br>

    <br><br>
    Team<br>
    <strong>'.$project.'</strong><br>
    </div>
    </div>
    </body>
    </html>';

    // Set content-type header for sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // Additional headers
    $headers .= 'From: info@gatewaypropmart.com'  . "\r\n";

    // Send email
    mail($to,$subject,$htmlContent,$headers);

    //end email
    header('Location: thanks.html');
}
?>