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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<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>

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 *

intersoluble-feminacy