Enquiry Page with IP and Location Tracker Using PHP

By | January 2, 2014

Enquiry page in a website is indeed, enquiry page is the very shortest way for visitor to communicate with the website team. Tracking the location and IP address of the visitor, who send enquiry may help website team, where is the visitor is from?. Here is the tutorial for how to track visitor from enquiry page using php.

 

Enquiry Page with IP and Location Tracker Using PHP jQuery

Enquiry Page with IP and Location Tracker Using PHP jQuery

 

NOTE: Any type of validation is not included in this script

PHP Code

[code type=php]

<html>
<head>
<?php
require_once(“ip.codehelper.io.php”);
require_once(“php_fast_cache.php”);

if(isset($_POST[‘submit’]))
{
$_ip = new ip_codehelper();
$real_client_ip_address = $_ip->getRealIP();
$visitor_location = $_ip->getLocation($real_client_ip_address);

$guest_ip = $visitor_location[‘IP’];
$guest_country = $visitor_location[‘CountryName’];
$guest_city = $visitor_location[‘CityName’];
$guest_state = $visitor_location[‘RegionName’];

$name=mysql_real_escape_string($_POST[‘name’]);
$email=mysql_real_escape_string($_POST[’email’]);
$msg=mysql_real_escape_string($_POST[‘descr’]);

$to=”YOURMAIL@MAIL.COM”;
$subject = “Enquiry Mail”;
$headers .= “MIME-Version: 1.0\r\n”;
$headers .= “Content-Type: text/html; charset=ISO-8859-1\r\n”;

$message = ‘<html><body>’;
$message.='<h1>Enquiry Mail</h1>’;
$message.='<div style=”border: 10px solid #0095DE; padding: 10px;”><br/>’;
$message.='<table><tr><td><b>From</b></td><td>’.$name.'</td></tr>’;
$message.='<tr><td><b>Email</b></td><td>’.$email.'</td></tr>’;
$message.='<tr><td><b>Message</b></td><td>’.$msg.'</td></tr></table>’;
$message.=’__________________________________________________<br/><br/><h2><b>Visitor Details</h2>’;
$message.='<div style=”margin:10px 0;”><b>IP Address</b>&nbsp;&nbsp;&nbsp;&nbsp;’.$guest_ip.'</div>’;
$message.='<div style=”margin:10px 0;”><b>Country</b>&nbsp;&nbsp;&nbsp;&nbsp;’.$guest_country.'</div>’;
$message.='<div style=”margin:10px 0;”><b>State</b>&nbsp;&nbsp;&nbsp;&nbsp;’.$guest_state.'</div>’;
$message.='<div style=”margin:10px 0;”><b>City</b>&nbsp;&nbsp;&nbsp;&nbsp;’.$guest_city.'</div></div>’;
$message.='</body></html>’;

if(mail($to,$subject,$message,$headers))
{
echo “<script type=’text/javascript’>alert(‘Thank you, we have received your enquiry.’);</script>”;
}
}
?>
</head>
<body>
<form method=”post” action=””>

<b>Name</b>
<input type=”text” name=”name” id=”name3″ />

<b>Email</b>
<input type=”text” name=”email” id=”email” />

<textarea></textarea>

<input type=”submit” name=”submit” id=”submit”/>
</form>
</body>
</html>

[/code]

4 thoughts on “Enquiry Page with IP and Location Tracker Using PHP

  1. Akila

    Hi. . Location tracking is not working for me. Failed to connect mail server. Plz reply

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *