How to capture client IP address in Php email form using $_SERVER[REMOTE_ADDR’]

Here’s a simple way of capturing IP Addresses from an Email Form:
1. You should have a working email form already.
2. Use this code/variable in your ‘post’ send.php file. This is the second file to execute your form.
$ip = $_SERVER[‘REMOTE_ADDR’]
3. To echo this in your email, use:
IP: $ip \n

——————

Example:

<?php
$mailto = ‘myemail@gmail.com’ ;

$name = $_REQUEST[‘name’] ;
$email = $_REQUEST[’email’] ;
$phone = $_REQUEST[‘phone’] ;
$message = $_REQUEST[‘message’] ;
$ip = $_SERVER[‘REMOTE_ADDR’] ;

$subject = “FROM SITE CONTACT FORM” ;

$message=”
Name: $name \n
Email: $email \n
Phone: $phone \n
Message: $message \n
IP: $ip \n
“;

$from=”From: $name\r\n”;

mail($mailto, $subject, $message, $from);
header( “Location:thanks.html” );
?>

————-

Good Luck.