Reputation:
I am using mail function in php, how to track or find the IP address
of email sender.
here is my code.
mail($to,$subject,$message);
all parameter came from view page using $_POST
.
Upvotes: 1
Views: 2050
Reputation: 24354
Check this answer https://stackoverflow.com/a/3358212/829533
Make a function in php
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
and add ip address to the email
$message = "IP Address: " . getUserIpAddr();
mail($to,$subject,$message);
Upvotes: 3