Page 1 of 1

Help on how to access a users mail box from PHP [Solved]

Posted: Tue Sep 19, 2006 6:13 am
by Kadanis
Hi all

As part of the app I'm working on I need to be able to access a mail box and parse the contents then return info to the user.

The mail side of things is set up now, and I can send and recieve just fine, however when attempting to use the imap_ commands in PHP I seem to be getting no-where.

The actual code I'm attempting to use is

Code: Select all

$user = "post";
$password  = "posting";

$mbox = imap_open({localhost/pop3:110}INBOX", $user, $password) or die (imap_last_error());

echo "<h1>Mailboxes</h1>\n";

$folders = imap_listmailbox($mbox, "{localhost/pop3:110}INBOX", "*");


if ($folders == false) {
   echo "Call failed<br />\n";
} else {
   foreach ($folders as $val) {
       echo $val . "<br />\n";
   }
}

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
   echo "Call failed<br />\n";
} else {
   foreach ($headers as $val) {
       echo $val . "<br />\n";
   }
}

imap_close($mbox);
however nothing seems to happen. No error and no return on the process happen. Just a blank page.

The server info is

OS = Fedora Core 4
PHP = 5.0.4

I installed the RPM for c-client (which I think is right) using webmin to get the Imap dev tools onto the server...


Please note that I'm a complete Linux noob/novice so please make any answers that pertain to the OS as thorough as poss ;) Cheers


Thanks All

D

Posted: Tue Sep 19, 2006 6:47 am
by impulse()
I'm no coding expert so I can't help you with that. Try and telnet to port 110 from a shell and see if it connects. If it does I can't help you any further. If it doesn't then that's probably going to be the problem.

Regards,

Posted: Tue Sep 19, 2006 7:27 am
by Kadanis
apologies for being a bit of a noob, but here goes... i opened telnet (from the start | run) and attempted to connect to port 110 on the server (which is on the same internal network as my windows desktop machine), but everytime i try to connect the CMD window just hangs. it doesn't say it's connected or that its failed...

assuming that there is a problem with port 110, how do i open it up on linux?

edit >> just tried "telnet localhost [110]" from the terminal window (no quotes) and it returns an error bad port... any ideas? thanks

Posted: Tue Sep 19, 2006 8:46 am
by Kadanis
Just in case anyone comes across this now, this has been sort. A bit more research on my part and a bit of luck and it seems to be ok...

1. Check IMAP is installed for PHP. On Fedora Core 4 this can be done with the command yum install php-imap

2. Check that the POP3/IMAP server is running to listen for connections. I used Dovecot.

3. Read up on the IMAP_ commands on the php.net site (these work for pop3 as well) and you should get somewhere. I am now using a the code above to connect to a mail box and read the contents.

Just in case anyone does try and use the code from this thread I had to tweak the following :

$mbox = imap_open({localhost/pop3:110}INBOX", $user, $password) or die (imap_last_error());

to this

$mbox = imap_open("{localhost/pop3:110/notls}INBOX", "user", "pass") or die (imap_last_error());

for a successful connection...

D

Posted: Tue Sep 19, 2006 11:57 am
by impulse()
No worries. Anytime.