<?
	/**
 	* name: 		 support.php
 	* dateļ¼?		 2011-03-16 
 	* authorļ¼?	 zhangj
 	* description: Best Bulk Emailer Track Service
		After you send your email newsletter, do you wonder what happens to your email next? 
		Is it delivered? Opened? Links clicked?
		Our track service is the process of recording every recipientās action on your mass 
		email campaigns. When a subscriber opens your email or clicks a link in your message, 
		his action is recorded and stored inside the email tracking system database.
		You can collect a full range of useful statistics on your email blasts:
			 1.  Open rate (ratio of unique opens as a percentage of emails sent)
			 2.  Click-through rate (ratio of unique clicks as a percentage of emails sent)
			 3.  Click-to-open rate (ratio of unique clicks as a percentage of unique opens)
			 4.  Number of total and unique email opens.
			 5.  Number of total and unique email clicks.
			 6.  Recipients'email addresses who opened your email.
			 7.  Recipients'email addresses who clicked on the links in your email.
			 8.  Which links were clicked.
 	*/
	$Email = $_GET["E"];	
	$TGuid = $_GET["T"];
  if ($TGuid == ""){
    	$TGuid = $_GET["amp;T"];
  }
	$Url = $_GET["U"];
  if ($Url == ""){
    	$Url = $_GET["amp;U"];
      }
  if($Email == "%{CURRENT_RCPTADDR}"){
      exit(-1);
      }
      
	if($Email == "" || $TGuid == ""){
		exit(-1);
	}
	$tracehost=getTraceHost("t1.wdmail.net");	
	if($tracehost == ""){
			$Url = base64_decode($Url);
			die_url($Url,"");
	}
	if ($Url == "")
	{
		$RedUrl="Location: http://".$tracehost."/read.php?E=";
		$RedUrl.= $Email;
		$RedUrl.= "&T=" . $TGuid;
		Header($RedUrl);   
	}
	else
	{
		$RedUrl="Location: http://".$tracehost."/url.php?E=";
		$RedUrl.= $Email . "&T=" . $TGuid  ."&U=" . $Url;
		Header($RedUrl);   
	}
		
	function die_url($url,$msg){
		echo $msg;
		echo "<script language='javascript'> window.location='$url'; </script>";
		die("");
	}
	
	function getTraceHost($hostname){
		$ifonline='';
		$tracehost='';
			
		$fp = fsockopen("$hostname", 80, $errno, $errstr, 10);
		if (!$fp) {
				;
		} else {
		    $out = "GET /check.php?Type=1&277348664: HTTP/1.1\r\n";
		    $out .= "Host: $hostname\r\n";
		    $out .= "Connection: Close\r\n\r\n";
		    fwrite($fp, $out);
		    while (!feof($fp)) {
		    		$online = fgets($fp);
		    		$pos=strstr($online,"tracehost=");
		    		if($pos == false){
		    				;
		    		}else{
		    			$online = str_replace("\r\n","",$online);
		    			$online = str_replace("\n","",$online);
		    			$pieces = explode("=", $online);
		    			$tracehost = $pieces[1];
		    			break;
		    		}
		    }
		    fclose($fp);
		}
		return $tracehost;
	}
?>
