<?php

if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        //ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        //ip pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
        $ip = $_SERVER['REMOTE_ADDR'];
    }

    $ipdat = @json_decode(file_get_contents(
        "http://www.geoplugin.net/json.gp?ip=" . $ip));
    


// echo 'Country Name: ' . $ipdat->geoplugin_countryName . "<br>";
// echo 'City Name: ' . $ipdat->geoplugin_city . "<br>";
// echo 'Continent Name: ' . $ipdat->geoplugin_continentName . "<br>";
// echo 'Latitude: ' . $ipdat->geoplugin_latitude . "<br>";
// echo 'Longitude: ' . $ipdat->geoplugin_longitude . "<br>";
// echo 'Currency Symbol: ' . $ipdat->geoplugin_currencySymbol . "<br>";
// echo 'Currency Code: ' . $ipdat->geoplugin_currencyCode . "<br>";
// echo 'Timezone: ' . $ipdat->geoplugin_timezone;

//client ifo
$ipaddress=$ip;
$country=$ipdat->geoplugin_countryName;
$city=$ipdat->geoplugin_city;
$timeZone=$ipdat->geoplugin_timezone;
//endinfo

// $emailaddress='';
$data='<table style="width:100%; border: 1px solid black; border-collapse: collapse;">
<tr>
<th style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 700;">Fields</th>
<th></th>
<th style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 700;">Value</th>
</tr>
';
foreach($_POST['quote'] as $key=>$value){

    $_key=ucwords(str_replace('_',' ',$key));
    if($key == 'email'){
        $emailaddress = $value;
    }
    if($value != ''){
        $data.='<tr>
        <td style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 500;">'.$_key.'</td>
        <td></td>
        <td style=" border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px">'.$value.'</td>
        </tr>';
    }
}
 $data.='<tr>
    <td style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 500;">IP</td>
    <td></td>
    <td style=" border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px">'.$ipaddress.'</td>
    </tr>
    <tr>
    <td style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 500;">Country</td>
    <td></td>
    <td style=" border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px">'.$country.'</td>
    </tr>
    <tr>
    <td style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 500;">City</td>
    <td></td>
    <td style=" border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px">'.$city.'</td>
    </tr>
    <tr>
    <td style="border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px; font-weight: 500;">Time Zone</td>
    <td></td>
    <td style=" border: 1px solid black; border-collapse: collapse; padding: 12px; text-align: left; font-size:15px">'.$timeZone.'</td>
    </tr>';
  
$subject="Ignite Design Pro";
$data.='</table>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

if (strpos(strtolower($emailaddress), 'noreply') !== false) {
    header('Location:thankyou.php');
}
else if(strpos(strtolower($emailaddress), 'no-reply') !== false){
    header('Location:thankyou.php');
}
else{
    mail("ignitedesignpro@gmail.com",$subject,$data,$headers);
  mail("mubeen.shargil@gmail.com",$subject,$data,$headers);
   $mailsent=mail("seanbrown@mobifyapps.com",$subject,$data,$headers);
        if($mailSent){
        header('Location:thankyou.php');
        echo json_encode(['status'=>'1','data'=>'Mail Sent']);
        } else {
            header('Location:thankyou.php');
            echo json_encode(['status'=>'0','data'=>'Some error occured']);
        }
}




?>