aaronmagic
asked on
PHP Contact Form - Obtain IP Address
I have a PHP contact form on my site which does work. I want a way to get a users IP address discretly sent to my email when the click SUBMIT on my form. I have tried various lines of code to do this to no avail. I am a novice so can someone please send me some step-by-step instructions on how to do this? That would be greatly appreciated.
Thanks,
aaronmagic
Thanks,
aaronmagic
Full code would be:
email.htm
=======
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
sendmail.php
==========
<?
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$ip = $_SERVER['REMOTE_ADDR'];// returns IP.
$message .= "\nIP is ".$ip;
mail( "yourname@example.com", "Web Mail",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
?>
email.htm
=======
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
sendmail.php
==========
<?
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$ip = $_SERVER['REMOTE_ADDR'];//
$message .= "\nIP is ".$ip;
mail( "yourname@example.com", "Web Mail",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
?>
ASKER
I must be doing something wrong. I added the code you said but when I click submit I still get the form but no IP address. Here is what my code looks like. Can you please alter it to fit?
Thanks,
aaronmagic
<?php
$sendTo = "admin@thisisatest.com";
$subject = "My Flash site reply";
while ($request = current($_REQUEST)) {
if (key($_REQUEST)!='recipien t') {
$pre_array=split ("&777&", $request);
$post_vars[key($_REQUEST)] [0]=$pre_a rray[0];
$post_vars[key($_REQUEST)] [1]=$pre_a rray[1];
}
next($_REQUEST);
}
reset($post_vars);
$subject="From ".$post_vars['your_name'][ 0] ;
$headers= "From: ".$post_vars['your_email'] [0] ."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
$message='';
while ($mess = current($post_vars)) {
if ((key($post_vars)!="i") && (key($post_vars)!="your_em ail") && (key($post_vars)!="your_na me")) {
$message.="<strong>".$mess [1]."</str ong> &nbs p;".$mess[ 0]."<br>";
}
next($post_vars);
}
mail($sendTo, $subject, $message, $headers);
?>
"Your message has been sent!"
<script>
resizeTo(300, 300);
</script>
Thanks,
aaronmagic
<?php
$sendTo = "admin@thisisatest.com";
$subject = "My Flash site reply";
while ($request = current($_REQUEST)) {
if (key($_REQUEST)!='recipien
$pre_array=split ("&777&", $request);
$post_vars[key($_REQUEST)]
$post_vars[key($_REQUEST)]
}
next($_REQUEST);
}
reset($post_vars);
$subject="From ".$post_vars['your_name'][
$headers= "From: ".$post_vars['your_email']
$headers.='Content-type: text/html; charset=iso-8859-1';
$message='';
while ($mess = current($post_vars)) {
if ((key($post_vars)!="i") && (key($post_vars)!="your_em
$message.="<strong>".$mess
}
next($post_vars);
}
mail($sendTo, $subject, $message, $headers);
?>
"Your message has been sent!"
<script>
resizeTo(300, 300);
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just read the question again, this will display it in the browser the previous method emailed it to you.
"Your message has been sent from IP <?php echp $_SERVER['REMOTE_ADDR']; ?>!"
<script>
resizeTo(300, 300);
</script>
"Your message has been sent from IP <?php echp $_SERVER['REMOTE_ADDR']; ?>!"
<script>
resizeTo(300, 300);
</script>
ASKER
Beautiful!!!! Adding
$ip = $_SERVER['REMOTE_ADDR'];// returns IP.
$message .= "\nIP is ".$ip;
Did the trick. TY!!! Much appreciated!!!
- aaronmagic
$ip = $_SERVER['REMOTE_ADDR'];//
$message .= "\nIP is ".$ip;
Did the trick. TY!!! Much appreciated!!!
- aaronmagic
$ip = $_SERVER['REMOTE_ADDR'];//
$message = "your message\nIP is ".$ip;
$email = "from@email.com";
mail( "yourname@example.com", "Subject",
$message, "From: $email" );
?>