Imap.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Heanup\App\Api\Controller;
  3. use Heanup\App\Api\RestfulController;
  4. use PhpImap\Exceptions\InvalidParameterException;
  5. use PhpImap\Mailbox;
  6. class Imap extends RestfulController
  7. {
  8. /**
  9. * Get Method|获取数据
  10. * @return void
  11. * @throws InvalidParameterException
  12. */
  13. protected function getData()
  14. {
  15. // Create PhpImap\Mailbox instance for all further actions
  16. $mailbox = new Mailbox(
  17. '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
  18. 'chendeben@a4sky.com', // Username for the before configured mailbox
  19. '6485882', // Password for the before configured username
  20. __DIR__, // Directory, where attachments will be saved (optional)
  21. 'UTF-8' // Server encoding (optional)
  22. );
  23. // Get all emails (messages)
  24. // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php
  25. $mailsIds = $mailbox->searchMailbox('ALL');
  26. // Get the first message
  27. // If '__DIR__' was defined in the first line, it will automatically
  28. // save all attachments to the specified directory
  29. $mail = $mailbox->getMail(26);
  30. // Show, if $mail has one or more attachments
  31. // echo "\nMail has attachments? ";
  32. // if ($mail->hasAttachments()) {
  33. // echo "Yes\n";
  34. // } else {
  35. // echo "No\n";
  36. // }
  37. echo ($mail->textHtml);
  38. // Print all information of $mail
  39. // print_r($mail);
  40. // Print all attachements of $mail
  41. // echo "\n\nAttachments:\n";
  42. // print_r($mail->getAttachments());
  43. }
  44. /**
  45. * Post Method|新增数据
  46. * @return void
  47. */
  48. protected function postData()
  49. {
  50. // TODO: 需要实现 postData() 方法.
  51. }
  52. /**
  53. * Put Method|更新数据
  54. * @return void
  55. */
  56. protected function putData()
  57. {
  58. // TODO: 需要实现 putData() 方法.
  59. }
  60. /**
  61. * Delete Method|删除数据
  62. * @return void
  63. */
  64. protected function deleteData()
  65. {
  66. // TODO: 需要实现 deleteData() 方法.
  67. }
  68. }