greenguy Posted January 8, 2011 Share Posted January 8, 2011 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 More sharing options...
fesan Posted January 8, 2011 Share Posted January 8, 2011 I can't point my finger at the exact error but the $ip somehow get lost i the sprint function. Read a bit about the function but i cant get no luck with printing the IP. Link to comment https://forums.phpfreaks.com/topic/223793-remote_address-problem/#findComment-1156825 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 I suspect it's something to do with the `$` before IP in here: $fields{"$IP"} = "VisitorIP"; Link to comment https://forums.phpfreaks.com/topic/223793-remote_address-problem/#findComment-1156845 Share on other sites More sharing options...
greenguy Posted January 8, 2011 Author Share Posted January 8, 2011 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]); } Link to comment https://forums.phpfreaks.com/topic/223793-remote_address-problem/#findComment-1156846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.