1

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.

Linga
  • 10,379
  • 10
  • 52
  • 104

1 Answers1

3

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);
Community
  • 1
  • 1
zzlalani
  • 22,960
  • 16
  • 44
  • 73