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.

1
  • 3
    Umm append $_SERVER["REMOTE_ADDR"] to your $message? Commented Jan 30, 2014 at 7:33

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

1 Comment

you help hacker spoof ip easily by sening fake HTTP_X_FORWARDED_FOR, its better log all this ips