On Tue, Sep 08, 2009 at 03:27:05AM +0900, Dave M G wrote: > Paul, > > Is there a decent tutorial anywhere on the net for the pop3.class.inc > available on phpclasses.org? > > http://www.phpclasses.org/browse/package/1120.html > > Maybe I'm blind, but I just can't find anywhere a decent description or > tutorial of what calls you can make to its functions. The documentation > file has two sections in German and a terse section in English. > > I'm trying to figure out how to get each message and get their subject > line, from address, and then based on those two pieces of information, > I'll take the whole body and store them in the right place in a MySQL > database. > > Just for reference, this is what I've built so far (I renamed > pop3.class.inc to POP3.php): > > include('POP3.php'); > $pop3 = new POP3(); > > // Connect to mail server > $do = $pop3->connect ('xxx.xxxxxxxxx.com'); > if ($do == false) > { > $message = $pop3->error; > } > > $do = $pop3->login ('uuuuuuuuuuu', 'ppppppppppp'); > > if ($do == false) > { > $message = $pop3->error; > } > > $status = $pop3->get_office_status(); > > if ($status == false) > { > die($pop3->error); > } > > $count = $status['count_mails']; > > > for ($i = 1; $i <= $count; $i++) > { > // Here's where I hit a wall. > // 1. Get the from address > // 2. Get the subject line > // 3. Get the header+body as one text file > // 4. Store it in the database. I'm not sure why you're attempting to do the above. According to the documentation, you should simply be able to do: for ($i = 1; $i <= $count; $i++) { $msg = $pop3->get_mail($i); // parse the message as you like $pop3->save2file($msg, 'myfilename.txt'); // or $pop3->save2mysql(a bunch of parameters); } The $msg is returned as an array of strings. You could use the PHP implode() function to reconstruct the array as a single string. But the POP3::save2file() function will do this and save it to a text file if you like. It appears the class doesn't provide any support for parsing the message internally. So that part is up to you. However, you could set up a loop like this: for ($j = 0; $j < count($msg); $j++) { if (strpos($msg[$i], 'Subject: ') == 0) // got the subject line if (strpos($msg[$i], 'From: ') == 0) // got the From: address line } Parsing the subject line and From: address is up to you. But there are plenty of PHP functions to search and parse strings. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php