haogood / php-imap
使用php imap扩展获取电子邮件内容和附件。
v1.0.1
2018-03-15 16:11 UTC
Requires
- php: >=5.5.0
- ext-imap: *
This package is not auto-updated.
Last update: 2024-09-29 23:41:23 UTC
README
要求
- PHP >= 5.5.0
- IMAP PHP 扩展
安装
composer require haogood/php-imap
初始化
use IMAP\IMAPMailbox; $host = '{imap.gmail.com:993/imap/ssl}'; $user = 'user@gmail.com'; $pwd = '******'; $mailbox = new IMAPMailbox($host, $user, $pwd);
搜索
$emails = $mailbox->search('ALL');
获取头部信息
foreach ($emails as $email) { // Header info $headerinfo = $email->fetchHeaderinfo(); // Author $author = $headerinfo->from->personal; // Sender address $from = $headerinfo->from->mailbox.'@'.$headerinfo->from->host; // Timestamp $timstamp = $headerinfo->udate; // Contents $contents = $email->getBody(); }
获取附件
foreach ($emails as $email) { foreach($email->getAttachments() as $attachment) { // Filename $filename = $attachment->getFilename(); // Extension $ext = $attachment->getExtension(); // Attachment file $file = $attachment->getBody(); // Attchment info $info = $attachment->getInfo(); } }
参考
许可证
haogood/php-imap
遵循MIT许可证(MIT)。