Retrieve email via POP3 with PEAR


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. // include class
  3. include("Net/POP3.php");
  4.  
  5. // initialize object
  6. $pop3 = new Net_POP3();
  7.  
  8. // attempt connection to server
  9. if (!$pop3->connect("example.com", 110)) {
  10. die("Error in connection");
  11. }
  12.  
  13. // attempt login
  14. $ret = $pop3->login("john", "doe");
  15. if (is_a($ret, 'PEAR_Error')) {
  16. die("Error in authentication: " . $ret->getMessage());
  17. }
  18.  
  19. // print number of messages found
  20. echo $pop3->numMsg() . " message(s) in mailbox\n";
  21.  
  22. // print message headers
  23. if ($pop3->numMsg() > 0) {
  24. for ($x=1; $x<=$pop3->numMsg(); $x++) {
  25. $hdrs = $pop3->getParsedHeaders($x);
  26. echo $hdrs['From'] . "\n" . $hdrs['Subject'] . "\n\n";
  27. }
  28. }
  29.  
  30. // disconnect from server
  31. $pop3->disconnect();
  32. ?>

URL: http://www.melonfire.com/community/columns/trog/print.php?id=275

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.