Page 1 of 1

Reading mail with PHP, IMAP versus POP + confi

Posted: Thu Jul 24, 2008 11:15 am
by JAB Creations
I decided I'm going to try and read email sent to a mail account on my live server though I could use a little help with what I should keep my focus on.

I know that there is imap and pop mail though I don't know much about how they work. So I looked at some tutorials to figure out the basic functions because I want to learn from the ground up and existing/working scripts are a good reference to go by. The imap_open function seemed to be a good place to start but I keep getting the following error...
Call to undefined function imap_open()
So after some searching on Google I read that it's a module (like cURL in example) that has to be installed and enabled. So I ran the following script which apparently will display modules enabled on the (live) server...

Code: Select all

<?php
echo "<pre>".implode("\n",get_loaded_extensions())."</pre>";
 
dl("imap.so");
if (extension_loaded("imap")) echo "<pre>imap loaded</pre>";
else echo "<pre>imap not loaded</pre>";
 
imap_open("server", "username", "password");
?>
That script gives me the following message...
Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/imap.so
Does this mean I can't use imap? Or pop? Nothing called pop is listed in the list but to maybe get the thread moving along quickly I'll post the list here now...
zip, xmlwriter, libxml, xmlrpc, dom, xmlreader, xml, tokenizer, session, pcre, SimpleXML, SPL, sockets, soap, SQLite, standard, Reflection, pspell, posix, mysqli, mysql, mime_magic, json, iconv, hash, gettext, gd, ftp, filter, exif, date, , url, ctype, calendar, bcmath, zlib, openssl, apache2handler, apc
Besides security and writing good code I don't really care about the "style" of fetching email from the server right now...if that is the only difference between pop and imap. I've done some reading on Wiki about them though a storm is forcing me to kind of rush through this post so I'll do more reading after the storm.

Any way I'm very open to suggestions for simply connecting to the mail server on my live host. This script once finished will only be used by me if that has any bearing on "style" choices (if there are any "style choices" in the sense of pop versus imap.

Re: Reading mail with PHP, IMAP versus POP + confi

Posted: Thu Jul 24, 2008 12:55 pm
by JAB Creations
It seems (that after an obnoxiously long thunderstorm) that imap is the way to go, that the module is not installed on my live server, and that RoundCube was somehow getting around this.

Testing out RoundCube I was going through the PHP code without much luck (excessive use of classes and code a little bit above my head at the moment) but it appears that RoundCube is able to get around needing the imap_open function by using fsockopen (this error spawned when I intentionally tested bad connection credentials). Can someone please be so kind as to confirm if I headed in the correct direction?

Re: Reading mail with PHP, IMAP versus POP + confi

Posted: Thu Jul 24, 2008 1:49 pm
by JAB Creations
I've successfully connected to the server as follows...

Code: Select all

$fp = @fsockopen("localhost", 993, $mail, $pass, 5);
if($fp) echo "<p>success</p>";
else echo "<p>failure: ".$errstr.'</p>';
...but I'm not sure where to go from here. I get "Resource id #2" if I echo $fp (and it doesn't seem to contain any array data). I know that I want to refer to the list of my email however all of the imap functions in PHp are unavailable so I'm not sure what is available that will bridge the connection between the email sitting right there in front of me. So in essence...what are my hands so I can look them up and figure it out from this point on?