Jump to content

Accessing IMAP server using fsockopen(), fgets(), and fputs()


Goldeneye

Recommended Posts

Well, I`m trying to create a script or class to interface PHP and MySQL with an IMAP server. I would use the PHP IMAP-Extension but because it isn`t a standard extension, it`s not complied on the Webserver I`m currently using.

 

What I currently have is...

$username = 'foo';
$password = 'bar';
$handle = fsockopen('localhost', 143, $errint, $errstr, 15);
$query = 'LOGIN {' . strlen($username) . "}\r\n$username". ' {' . strlen($password) . "}\r\n$password";
fputs($handle, $query);
$query = 'SELECT INBOX';
fputs($handle, $query);
$query = 'FETCH 8 BODY[]';
fputs($handle, $query);
echo fgets($handle);

 

I thought the code would work but all that is echo`d is * OK Dovecot ready.

 

So, how do I go about connecting to (and reading from) an IMAP Server using sockets?

because it isn`t a standard extension' date=' it`s not complied on the Webserver I`m currently using.[/quote']

 

http://pear.php.net/package/Mail_IMAP/download/All

You don't need access to the server's configuration or compilation. Just the include path.

Please excuse my ignorance:

 

Being a PEAR virgin, I really have no idea how to install this. I`ve looked at tutorials found through a Goolge Search, but I am finding them too ambiguous or simply not working for me.

 

I tried ''pear install Mail_IMAP-1.1.0RC2'' in a PuTTY session but that didn`t work.

 

How do I manually install it?

I just noticed, PEAR/Mail_IMAP and it`s v2 child both require the PHP IMAP Extension as a dependancy. This means, I can`t use it because the PHP IMAP extension is not installed; doesn't it?

 

Edit: It doesn`t appear to be working for me, anyway. I have setup my server-settings exactly as they should be but I still get, `Error: Unable to build a connection.`

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.