Jump to content

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


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.`

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.