home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / Net_POP3_example.php < prev    next >
Encoding:
PHP Script  |  2004-10-01  |  4.6 KB  |  153 lines

  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Copyright (c) 2002, Richard Heyes                                     |
  4. // | All rights reserved.                                                  |
  5. // |                                                                       |
  6. // | Redistribution and use in source and binary forms, with or without    |
  7. // | modification, are permitted provided that the following conditions    |
  8. // | are met:                                                              |
  9. // |                                                                       |
  10. // | o Redistributions of source code must retain the above copyright      |
  11. // |   notice, this list of conditions and the following disclaimer.       |
  12. // | o Redistributions in binary form must reproduce the above copyright   |
  13. // |   notice, this list of conditions and the following disclaimer in the |
  14. // |   documentation and/or other materials provided with the distribution.|
  15. // | o The names of the authors may not be used to endorse or promote      |
  16. // |   products derived from this software without specific prior written  |
  17. // |   permission.                                                         |
  18. // |                                                                       |
  19. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
  20. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
  21. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  22. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
  23. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  24. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
  25. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  26. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  27. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
  28. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  29. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
  30. // |                                                                       |
  31. // +-----------------------------------------------------------------------+
  32. // | Author: Richard Heyes <richard@phpguru.org>                           |
  33. // | Co-Author: Damian Fernandez Sosa <damlists@cnba.uba.ar>               |
  34. // +-----------------------------------------------------------------------+
  35. //
  36. // $Id: Net_POP3_example.php,v 1.1.1.1 2004/08/27 02:21:36 damian Exp $
  37. ?>
  38. <html>
  39. <body>
  40. <?php
  41.  
  42. include('Net/POP3.php');
  43.  
  44.  
  45.  
  46.  
  47. $user='richard';
  48. $pass='Alien3';
  49. $host='localhost';
  50. $port="110";
  51.  
  52. // you can create a file called passwords.php and store your $user,$pass,$host and $port values in it
  53. // or you can modify this script
  54. @include_once("./passwords.php");
  55.  
  56.  
  57.  
  58. // Create the class
  59.  
  60. $pop3 =& new Net_POP3();
  61.  
  62.  
  63. //$pop3->setDebug();
  64.  
  65. // Connect to localhost on usual port
  66. // If not given, defaults are localhost:110
  67.  
  68. if(PEAR::isError( $ret= $pop3->connect($host , $port ) )){
  69.     echo "ERROR: " . $ret->getMessage() . "\n";
  70.     exit();
  71. }
  72.  
  73.  
  74. // Login using username/password. APOP will
  75. // be tried first if supported, then basic.
  76.  
  77. //$pop3->login($user , $pass , 'APOP');
  78. //$pop3->login($user , $pass , 'CRAM-MD5');
  79.  
  80. if(PEAR::isError( $ret= $pop3->login($user , $pass,'USER' ) )){
  81.     echo "ERROR: " . $ret->getMessage() . "\n";
  82.     exit();
  83. }
  84.  
  85. /*
  86. if(PEAR::isError( $ret= $pop3->login($user , $pass ) )){
  87.     echo "ERROR: " . $ret->getMessage() . "\n";
  88.     exit();
  89. }
  90. */
  91. /*
  92. if(PEAR::isError( $ret= $pop3->login($user , $pass , 'CRAM-MD5') )){
  93.     echo "ERROR: " . $ret->getMessage() . "\n";
  94.     exit();
  95. }
  96. */
  97.  
  98.  
  99.  
  100.  
  101. // Get the raw headers of message 1
  102.  
  103. echo "<h2>getRawHeaders()</h2>\n";
  104. echo "<pre>" . htmlspecialchars($pop3->getRawHeaders(1)) . "</pre>\n";
  105.  
  106.  
  107. // Get structured headers of message 1
  108.  
  109. echo "<h2>getParsedHeaders()</h2> <pre>\n";
  110. print_r($pop3->getParsedHeaders(1));
  111. echo "</pre>\n";
  112.  
  113.  
  114. // Get body of message 1
  115.  
  116. echo "<h2>getBody()</h2>\n";
  117. echo "<pre>" . htmlspecialchars($pop3->getBody(1)) . "</pre>\n";
  118.  
  119.  
  120. // Get number of messages in maildrop
  121.  
  122. echo "<h2>getNumMsg</h2>\n";
  123. echo "<pre>" . $pop3->numMsg() . "</pre>\n";
  124.  
  125.  
  126. // Get entire message
  127.  
  128. echo "<h2>getMsg()</h2>\n";
  129. echo "<pre>" . htmlspecialchars($pop3->getMsg(1)) . "</pre>\n";
  130.  
  131.  
  132.  
  133.  
  134.  
  135. // Get listing details of the maildrop
  136.  
  137. echo "<h2>getListing()</h2>\n";
  138. echo "<pre>\n";
  139. print_r($pop3->getListing());
  140. echo "</pre>\n";
  141.  
  142.  
  143. // Get size of maildrop
  144.  
  145. echo "<h2>getSize()</h2>\n";
  146. echo "<pre>" . $pop3->getSize() . "</pre>\n";
  147.  
  148.  
  149. // Disconnect
  150.  
  151. $pop3->disconnect();
  152. ?>
  153.