pop3 php class - connection timed out

Status
Niet open voor verdere reacties.

beanbag

Gebruiker
Lid geworden
25 apr 2009
Berichten
54
In het "algemene" subforum van dit forum heb ik de vraag gesteld of het mogelijk was om hotmail emails te openen in je website.
Er werden me pop3 php classes aangeraden.

Ik heb er een gevonden (zie verder) en deze geupload naar een gratis php host samen met een testpagina (zie verder).

Als ik naar de testpagina surf krijg ik volgende error:

Warning: fsockopen() [function.fsockopen]: unable to connect to pop3.live.com:995 (Connection timed out) in /home/beanbag/public_html/pop3.php on line 11

Ik krijg ook andere errors maar die volgen denk ik uit het feit dat er geen verbinding is.

De parameters heb ik gehaald van een site waarin ze uitleggen hoe je je outlook account moet verbinden via pop3 aan hotmail.
Op die pagina stond ook dat je het via een ssl verbinding moet doen.

Dus heb ik (conform aan een scriptje dat ik ergens vond) 'ssl://pop3.live.com' als domein getypt. Dit had geen effect.

Wat doe ik verkeerd?


De volledige testpagina en klasse (paswoord verwijderd) staan hieronder, het gaat volgens mij echter om de parameters of de eerste paar lijnen van de klasse.

Bedankt !


Testpagina

PHP:
<?
error_reporting(E_ALL);
include('pop3.php');
$rPOP3handle = new pop3('pop3.live.com','gebruikersnaam@hotmail.com','paswoord',995);
print_r($rPOP3handle->retrieveMessage(1));
?>

Klasse
PHP:
<?
class pop3
	{
	private $rConnection, $sUser, $sPass, $sHost, $iPort, $sReturn;
	public function __construct($sHost,$sUser,$sPass,$iPort=110)
		{
		$this->sHost = $sHost;
		$this->iPort = $iPort;
		$this->sUser = $sUser;
		$this->sPass = $sPass;
		$this->rConnection = fsockopen($sHost,$iPort,$iErrorNum, $sErrorStr,5);
		if(substr(trim($this->sReturn = $this->stream_get_contents() ),0,3) != '+OK')
			{
			$this->throwError('fsockopen:'.$sErrorStr);
			return false;
			}
		$this->toSock('USER '.$sUser);
		$this->sReturn = trim($this->stream_get_contents());
		if(substr($this->sReturn,0,3) != '+OK')
			{
			return false;
			}
		$this->toSock('PASS '.$sPass);
		$this->sReturn = trim($this->stream_get_contents());
		if(substr($this->sReturn,0,3) != '+OK')
			{
			return false;
			}
		return true;
		}
	public function __destruct()
		{
		$this->toSock('QUIT');
		fclose($this->rConnection);
		}
	private function stream_get_contents($iLength = 512)
		{
		$sReturn = fread($this->rConnection,$iLength);
		return str_replace("\r\n","\n",$sReturn);
		}
	private function toSock($sStr)
		{
		if($this->rConnection)
			{
			if(fwrite($this->rConnection,$sStr."\n")===FALSE)
				{
				return false;
				}
			else
				{
				return true;
				}
			}
		else
			{
			$this->throwError('Geen verbinding');
			return false;
			}
		}
	private function throwError($sError)
		{
		echo '<br>
		<hr>
		Er is een fout opgetreden.<br>
		De volgende fout werd meegegeven:<br>'.$sError.'<hr>
		<br>';
		}
	public function deleteMessage($iBerichtNummer)
		{
		$this->toSock('DELE '.$iBerichtNummer);
		$this->sReturn = trim($this->stream_get_contents());
		return (substr($this->sReturn,0,3) == '+OK');
		}
	public function listMessages($iBerichtNummer = '')
		{
		if(!empty($iBerichtNummer))
			{
			if(!is_numeric($iBerichtNummer))
				{
				$this->throwError('Ongeldig berichtnummer!');
				return false;
				}
			else
				{
				$this->toSock('LIST '.$iBerichtNummer);
				$this->sReturn = trim($this->stream_get_contents());
				echo "\n".$this->sReturn."\n";

				if(substr($this->sReturn,0,3) != '+OK')
					{
					return false;
					}
				$aReturnData = explode(' ',$this->sReturn);
				return array($aReturnData[1] => $aReturnData[2]);
				}
			}
		else
			{
			$this->toSock('LIST');
			echo "\ntoSock('LIST')\n";
		$this->sReturn = trim($this->stream_get_contents());
			if(substr($this->sReturn,0,3) != '+OK')
				{
				return false;
				}
			ereg("^\+OK ([0-9]*) [aegms]{8} \(([0-9]*) [ceost]{6}\)(.*)\.$",$this->sReturn,$aMatch);
			if($aMatch[1] > 0)
				{
				$aResult[0] = array($aMatch[1] => $aMatch[2]);
				$aReturnData = explode("\n",$this->sReturn);
				foreach($aReturnData as $sRij)
					{
					$aRij = explode(' ',$sRij);
					if(count($aRij) == 2)
						{
						$aResult[$aRij[0]] = $aRij[1];
						}
					}
				}
			else
				{
				$aResult = array(0=>array(0=>0));
				}
			return $aResult;
			}
		}
	public function retrieveMessage($iBerichtNummer)
		{
		$this->toSock('RETR '.$iBerichtNummer);
		$this->sReturn = trim($this->stream_get_contents());
		if(substr($this->sReturn,0,3) != '+OK')
			{
			$aReturn = false;
			}
		else
			{
			if(ereg("^\+OK ([0-9]*) [ceost]{6}\n(.*)\n\.",$this->sReturn,$aMatch))
				{
				//aMatch[1] => totale grootte bericht
				//aMatch[2] => totale bericht
				
				// is het bericht groter dan 500 bytes
				// Ja? dan is nog niet het hele bericht uitgelezen
				if($aMatch[1] > 502)
					{
					$aMatch[2] .= stream_get_contents($aMatch[1] - 512);
					}
				// Headers+bericht
				$aReturn['message'] = $aMatch[2];
				// headers worden afgesloten met een dubbele newline.
				$aReturnData = explode("\n\n",$aMatch[2]);
				$aReturn['headers'] = $aReturnData[0];
				$iHeaderLength = strlen($aReturnData[0]);
				// lengte die overblijft na het afknippen van de headers
				$aReturn['body'] = substr($aMatch[2],$iHeaderLength+2);
				}
			else
				{
				// ereg vond geen matchniet.
				$this->throwError('System: POP3-Server returned an invalid messageformat!');
				echo $this->sReturn;
				return false;
				}
			}
		return $aReturn;
		}
	}
?>
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan