项目作者: dcblogdev

项目描述 :
IMAP class for reading imap emails with PHP
高级语言: PHP
项目地址: git://github.com/dcblogdev/imap.git
创建时间: 2016-11-27T10:41:01Z
项目社区:https://github.com/dcblogdev/imap

开源协议:MIT License

下载


Latest Version on Packagist
Total Downloads

Logo

IMAP class for reading IMAP emails with PHP

Example usage:

  1. use Dcblogdev\Imap\Imap;
  2. //set search criteria
  3. $date = date('d-M-y', strtotime('1 week ago'));
  4. $term = 'ALL UNDELETED SINCE "'.$date.'"';
  5. //ignore array of emails
  6. $exclude = [];
  7. $email = 'someone@domain.com';
  8. $password = 'emailpassword';
  9. $host = 'outlook.office365.com';//your email host
  10. $port = '993';//port number
  11. $savePath = "emails";//folder to save attachments
  12. $markAsSeen = true;//when true mark email as been read
  13. $delete = false;//set to true to delete email
  14. //initialise email
  15. $imap = new Imap($email, $password, $host, $port, 'Inbox', $savePath, $markAsSeen, $delete);
  16. //get emails pass in the search term and exclude array
  17. $emails = $imap->emails($term, $exclude);
  18. //loop over emails and display
  19. foreach($emails as $email) {
  20. echo "Account {$email['account']}<br>";
  21. echo "Subject {$email['subject']}<br>";
  22. echo "From {$email['fromName']} ({$email['fromAddress']})<br>";
  23. echo "To {$email['toAddress']}<br>";
  24. echo "CC {$email['ccAddress']}<br>";
  25. echo "Date {$email['emailDate']}<br>";
  26. echo count($email['attachments'])." Attachments<br>";
  27. foreach($email['attachments'] as $attachment) {
  28. echo "<a href='{$attachment['file']}'>{$attachment['fileName']}</a>";
  29. }
  30. echo "<br><br>";
  31. if ($email['htmlBody'] !='') {
  32. echo $email['htmlBody'];
  33. } else {
  34. echo nl2br($email['plainBody']);
  35. }
  36. echo "<hr>";
  37. }