Hello!
I am using fsockopen() to connect to a mail server (POP3) and download some emails.
I am able to connect to the server and receive the '+OK connected to mail server' message. After i have received this, i cannot try to receive anything else otherwise the script will time out.
Here is my code;
$UserName = "testing";
$Password = "testing";
$Address = "pop3.domain.com";
$Port = 110;
$SckRes = fsockopen ($Address, $Port, $errno, $errstr, 30);
If($SckRes){
$Initial = FGets($SckRes, 1024);
Echo "$Initial<br>";
If(substr($Initial, 0, 3) == "+OK"){
echo "Connected<br>";
FPuts($SckRes, "USER" . $UserName);
USleep(200000);
FPuts($SckRes, "PASS" . $Password);
USleep(200000);
//
//Times out around here!!
//
If(!FEOF($SckRes)){
Echo FRead($SckRes, 1024);
}
FPuts($SckRes, "LIST");
USleep(200000);
Echo FGets($SckRes, 1024);
FPuts($SckRes, "QUIT");
USleep(200000);
}else{
echo "Not OK<br>";
}
}else{
// Unable to connect.
Echo "$errno, $errstr";
}
I have added everything, hope it isnt too confusing...
As you can see from where i put the comment, the script times out (30 seconds) when i try to read/get any data. I have no way of telling if the username/password was sent ok, and i dont know why it doesnt work.
I wrote a test program in VB6, and data was sent between the 2 scripts with no problem at all (VB program was giving out 'expected' data though...)
My guess is that the server hasnt got any data to send, so the script cannot receive it? I added FEOF() but to no avail.
Does anyone have any ideas?? Does anyone know of any code samples anywhere? lol - worth a try.
Perhaps i should be using 'propper' sockets instead?
Thanks for your time!
Kold.