How to post ip address AND city

How would I be able to get not only the ip address of user but also the city to post in form-mail script?

brief part where I thought it would work


// Mail contents config
$return_ip[0]="yes";
     $return_ip[0]= $_SERVER['REMOTE_ADDR'];
    $details = json_decode(file_get_contents("http://ipinfo.io/{$return_ip}/json"));
    $details[0]="";	


// build verticle table format
	function buildVertTable($fields, $intro, $to, $send_ip)
	{
		$message=htmlHeader();
		if($intro != "")
			$message.="<tr>\
<td align=\\"left\\" valign=\\"top\\" colspan=\\"2\\">".$intro."</td>\
</tr>\
";
		$fields_check=preg_split('/,/',$fields);
		$run=sizeof($fields_check);
		for($i=0;$i<$run;$i++)
		{
			$cur_key=$fields_check[$i];
			$cur_value=$_POST[$cur_key];
			if(is_array($cur_value))
			{
				$cur_value=parseArray($cur_key);
			}
			$cur_value=parseValue($cur_value);
			if($allow_html[$config]=="no")
				$cur_value=htmlspecialchars(nl2br($cur_value));
			else
				$cur_value=nl2br($cur_value);
			$message.="<tr>\
<td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"><b>".$cur_key."</b></td>\
<td align=\\"left\\" valign=\\"top\\" width=\\"100%\\">".$cur_value."</td>\
</tr>\
";
		}
		if($send_ip=="yes" && $to=="recipient")
		{
			$user_ip=getIP();
			$message.="<tr>\
<td align=\\"left\\" valign=\\"top\\" style=\\"white-space:nowrap;\\"><b>Sender IP</b></td>\
<td align=\\"left\\" valign=\\"top\\" width=\\"100%\\">".$user_ip."</td>\
</tr>\
";
		}
		$message.=htmlFooter();
		return $message;
	}

I am new at php so dummy it down, please

Thanks

You are assuming the city to be returned is accurate when odds are it will not be. The IP lookup may return the city the person is in, the metropolitan area their traffic is routed through which can be many miles away, or another region entirely. That site is returning the metro area for me, which is 20 miles away from where I am.