Kevin Aartsen Kevin Aartsen - 5 months ago 15
PHP Question

Get users ip on page click

I'm trying to get my users ip address when they open a certain page.
I want this ip mailed to me or stored in the database.

At the moment I have this, but its not working.

<?php
$to = "flash1996mph@hotmail.com";
$subject = "test";
$ip = $_SERVER['REMOTE_ADDR'];
$txt = "Hello world!";

header ('mail($to,$subject,$txt,$ip);')
?>


I have no idea if this is right or wrong, I'm just a newby trying.. This was the first that came up in my mind.

All help is appreciated.

Thanks in advance,

-Kev

edit:

<?php
$to = "flash1996mph@hotmail.com";
$subject = "test";
$ip = $_SERVER['REMOTE_ADDR'];
$txt = "Hello world!";

mail($to,$subject,$txt,$ip);
?>


Got this now, and its still not working.
Whenever i remove the "ip" variable it works. When i don't it doesn't send.

Answer

You should not put the mail sending inside header change to this, also the fourth parameter is for headers :

$txt = "Hello your ip is ".$ip;


 mail($to,$subject,$txt); 
Comments