Php mailer form that detect ip address

Hi guys i don’t know anything about PHP but i am trying to add a piece of code to my mailer in order to detect the ip address of ppl emailing me.
this is the code, i am using flash to connect to the mailer.php

<?php

$sName = $_REQUEST[“senderName”];
$email = $_REQUEST[“sender”];
$subject = $_REQUEST[“subject”];
$message = $_REQUEST[“message”];

$message = "Name: " . $sName . “\r” . "Message: " . $message;

mail( “youname@yourdomain.com”, $subject, $message, “From: $email” );

?>

Someone else suggested me to add this to the php code
$ip=$_SERVER[‘REMOTE_ADDR’];
But i don’t know where and how this will work.
I am adding the fla file and the php to this post just in case someone can point me in the right direction.
Thank You
Max

Hi max999. Welcome to SitePoint. :slight_smile:

You can just place that $ip variable inside the PHP tags as shown in red, and you could do something like include the IP address in the message that is sent to you (shown in blue).

<?php
[COLOR="Red"]$ip=$_SERVER['REMOTE_ADDR'];[/COLOR]
$sName = $_REQUEST["senderName"];
$email = $_REQUEST["sender"];
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];

$message = "Name: " . $sName . "\\r" . "Message: " . $message . [COLOR="Blue"]"IP of sender: " . $ip[/COLOR];

mail( "youname@yourdomain.com", $subject, $message, "From: $email" );

?>

I only know the basics of this, so there may be a better way, but I’ve done it successfully this way before. :slight_smile:

works perfect, thanks so much.
Max

Great! I do this sometimes so that I can block the occasional spammer. You can do this by adding this between the PHP tags:

$blacklist = array( // add banned IPs to this list
    "127.0.0.1",
);

if(in_array($ip, $blacklist)) {
    echo "<h1>Avaunt, spammer!</h1>";
    exit ();
}