This is the code and in this code country is executed by IP address, and when it sends mail on my email address then it shows up "country: unknown" while it should send visitor's/sender's country name.
<?php
$fullName=$_REQUEST['fullName'];
$phnNumber=$_REQUEST['phnNumber'];
$enquery=$_REQUEST['enquery'];
$ipaddress = $_SERVER["REMOTE_ADDR"];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$pipaddress = getenv('HTTP_X_FORWARDED_FOR');
function visitor_country()
{
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
$result = "Unknown";
if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if($ip_data && $ip_data->geoplugin_countryName != null)
{
$result = $ip_data->geoplugin_countryName;
}
return $result;
}
$to="matt@mb-adi-drivingschool.co.uk";
$subject = "Contact Us form Details";
$message = "\nFull Name : ".$fullName."\n Phone Number:".$phnNumber."\n General Enquiry : ".$enquery."\n IP Address : ".$ipaddress."\n Host name : ".$hostname."\n Proxy IP Address : ".$pipaddress."\n Country : ".visitor_country()." \n ";
$from="matt@mb-adi-drivingschool.co.uk";
@mail($to,$subject,$message,"From:$from");
@header("location:thankyou.php");
?>