burpitt Posted February 3, 2012 Share Posted February 3, 2012 Elo fellow presta'ers... I would like to add the IP of the client who is using the contact form on my shop, so that when I receive the contact form email (to which ever employee is set) it gives the IP of the person who sent the contact email. I can't imagine this is too hard but instead of butchering it I thought I'd try and do it the right way. Any suggestions? Obviously the client who receives their own copy does not need to have their IP shown necessarily. Thanks for your help and suggestions. Link to comment Share on other sites More sharing options...
burpitt Posted February 28, 2012 Author Share Posted February 28, 2012 Any insights people? Thanks. Link to comment Share on other sites More sharing options...
sebkos Posted February 28, 2012 Share Posted February 28, 2012 Hi, if nobody wants to help I give you short schedule: 1. add this to ContactController.php before Mail:: function $ip_address = Db::getInstance()->getValue(' SELECT cm.ip_address FROM '._DB_PREFIX_.'customer_message cm WHERE cm.id_customer_thread = '.(int)($id_customer_thread).' ORDER BY date_add DESC'); $ip = long2ip($ip_address); 2. add '{ip}' => $ip to Mail:: function 3. edit 'contact' mail template and add IP: {ip} where you want Link to comment Share on other sites More sharing options...
burpitt Posted February 29, 2012 Author Share Posted February 29, 2012 Thanks for the reply Seb mate... I've added the modifications but the IP is reporting in tests emails as 0.0.0.0 ... its obviously not looking in the right place for the information :/ I looked into this more and with the help of my good friend LazyLegs he has come up with a close but different solution that works first time. 1. Add query code to ContactController.php - (I added this just before the $contact variable is set - line 104): if ( !empty($_SERVER['HTTP_CLIENT_IP']) ) { $ip = $_SERVER['HTTP_CLIENT_IP']; } else if ( !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } 2. Add '{ip}' => $ip to Mail:: function (line 116): if (Mail::Send((int)self::$cookie->id_lang, 'contact', Mail::l('Message from contact form', (int)self::$cookie->id_lang), array('{email}' => $from, '{ip}' => $ip, '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment) 3. Edit mail template and add {ip} selector (default template is contact.html in domain.com/mails/..) Hope this helps someone else out, very simple and easy to add when you know how! Link to comment Share on other sites More sharing options...
sebkos Posted February 29, 2012 Share Posted February 29, 2012 Hi again, did you test it on localhost? IP address 0.0.0.0 is one of localhost alias used by system. Link to comment Share on other sites More sharing options...
davers44 Posted March 30, 2013 Share Posted March 30, 2013 Any news on that? It would be very helpful... is there a module that include ip address and maybe City and Contry in the contact email? Thanks Link to comment Share on other sites More sharing options...
El Patron Posted March 30, 2013 Share Posted March 30, 2013 prestashop function Tools::getRemoteAddr() will return the IP address for you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now