title: track recipient IP address through mail inphp
body: <p>I want to find the IP address of recipient whom I sent a mail after opening it. I can tract down whether he has open my email or not but not getting proper IP address of the client.</p>
  
  <p>In my php code I have created a dynamic image path to track the IP address.</p>
  
  <pre><code> &lt;img border="0" height="150" src="http://www.ogmaconceptions.com/tracking.php?email=&lt;?php echo $client_email?&gt;" width="100" /&gt;
  </code></pre>
  
  <p>And in my tracking.php I have used this code to track IP and create image dynamically.</p>
  
  <pre><code>public function getRealIP() {
          $ipaddress = '';
          if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
              $ipaddress =  $_SERVER['HTTP_CF_CONNECTING_IP'];
          } else if (isset($_SERVER['HTTP_X_REAL_IP'])) {
              $ipaddress = $_SERVER['HTTP_X_REAL_IP'];
          }
          else if (isset($_SERVER['HTTP_CLIENT_IP']))
              $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
          else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
              $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
          else if(isset($_SERVER['HTTP_X_FORWARDED']))
              $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
          else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
              $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
          else if(isset($_SERVER['HTTP_FORWARDED']))
              $ipaddress = $_SERVER['HTTP_FORWARDED'];
          else if(isset($_SERVER['REMOTE_ADDR']))
              $ipaddress = $_SERVER['REMOTE_ADDR'];
          else
              $ipaddress = 'UNKNOWN';
  
          return $ipaddress;
      }
  
  function LoadJpeg($imgname)
  {
      /* Attempt to open */
      $im = @imagecreatefromjpeg($imgname);
  
      /* See if it failed */
      if(!$im)
      {
          /* Create a black image */
          $im  = imagecreatetruecolor(150, 30);
          $bgc = imagecolorallocate($im, 255, 255, 255);
          $tc  = imagecolorallocate($im, 0, 0, 0);
  
          imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
  
          /* Output an error message */
          imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
      }
  
      return $im;
  }
  header('Content-Type: image/jpeg');
  
  $img = LoadJpeg('images/OC-logo.jpg');
  
  imagejpeg($img);
  imagedestroy($img);
  </code></pre>
  
  <p>I am getting the IP but the IP of Email server of recipient, not the actual IP address of the recipient. Is there any tricks so that I can get the client IP as well.</p>
  
  <p>Thanks
  Amar</p>