Posted By

d4rk on 04/23/07


Tagged

php pear pop3 NetPOP3


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

vali29
mmccrack
thastyle


Retrieve email via POP3 with PEAR


 / Published in: PHP
 

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

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

Report this snippet  

You need to login to post a comment.