Jump to content

Add customer IP to contact email


burpitt

Recommended Posts

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

  • 4 weeks later...

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

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

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...