Jump to content

REMOTE_ADDRESS PROBLEM


greenguy

Recommended Posts

Hi,

 

I am new here ,so be gentle.........lol

 

The form below is on our site.

 

It works perfectly except it does not display the user's IP address in the email response to us.

 

I suspect it is the $body = "You have received the following inquiry from\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

How do I include the $IP value in the email response??

 

Thank you

 

<?php

 

 

 

 

       

   

$IP=$_SERVER['REMOTE_ADDR'];

 

$to = $_REQUEST['sendto'] ;

$from = $_REQUEST['Email'] ;

$name = $_REQUEST['Name'] ;

$address = $_REQUEST['Address'];

$servicetype = $_REQUEST['Servicetype'] ;

$serviceperiod = $_REQUEST['Serviceperiod'] ;

$headers = "From: $from";

$subject = "Website Inquiry";

 

 

 

 

$fields = array();

$fields{"Name"} = "Name"; 

$fields{"Email"} = "Email";

$fields{"Phone"} = "Phone";

$fields{"Address"} = "Address";

$fields{"Servicetype"} = "Servicetype";

$fields{"Serviceperiod"} = "Serviceperiod" ;

$fields{"Message"} = "Message";

$fields{"$IP"} = "VisitorIP";

 

$body = "You have received the following inquiry from\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

$headers2 = "From: [email protected]";

$subject2 = "No reply";

$autoreply = "Thank you for inquiring about our cleaning services.\n

I will get back to you as soon as possible, usually within the business day.\n

If you have any questions, you can also call me directly at 555-121-1212\n

 

 

Sarah

 

 

";

 

 

if($from == '') {print "You have not entered an email, please go back and try again";}

else {

if($name == '') {print "You have not entered a name, please go back and try again";}

else {

$send = mail($to, $subject, $body, $headers);

$send2 = mail($from, $subject2, $autoreply, $headers2);

if($send)

{header( "Location: http://www.example.com/thank-you-inquiry.html" );}

else

{print "We encountered an error sending your mail, please notify [email protected]"; }

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/223793-remote_address-problem/
Share on other sites

AHA!

 

You triggered a thought and were correct. The sprintf function I have only formats the $_REQUEST[$a] array and not the value of $IP.

 

I removed the $fields{"$IP"} = 'VisitorIP' and put the $IP in the body string as below. It works!!!

 

It's fixed now and works. Thank you for getting me thinking

 

 

$body = "You have received the following inquiry from $IP "; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.