定制 jord-jd/email-structure-parser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jord-jd/email-structure-parser

最新稳定版本:v4.0.0

Composer 安装命令:

composer require jord-jd/email-structure-parser

包简介

Email Structure Parser

README 文档

README

Given an IMAP stream and a message number, this library will parse the structure of multipart emails.

Installation

You can easily install the Email Structure Parser package using the following Composer command.

composer require jord-jd/email-structure-parser

Usage

To use this parser, you must have first connect to a mail server using PHP's built-in imap_open function. Once connected, you then need to retrieve a message number, via the imap_search function.

Once you have a message number, you can pass it, along with the IMAP stream object, into the EmailStructureParser. You can then call the getParts() method to retrieve an array of parsed email parts split up by mime type.

See the example usage code below.

use JordJD\EmailStructureParser\EmailStructureParser;

// Connect to mailbox
$imapStream = imap_open('{outlook.office365.com:993/ssl/novalidate-cert}INBOX', getenv('USERNAME'), getenv('PASSWORD'));

// Get a message number (in this example, just get the first)
$msgNums = imap_search($imapStream, 'ALL');
$msgNum = $msgNums[0];

// Load message into parser
$parser = new EmailStructureParser($imapStream, $msgNum);

// Get parsed multipart email parts - including plain text and/or HTML content, and any attachments
$parts = $parser->getParts();

// Output HTML email content
var_dump($parts['TEXT/HTML']);

// Save attached PNG images
foreach($parts['IMAGE/PNG'] as $image) {
    file_put_contents($image->name, $image->content);
}

Content IDs

Some emails embed images into the HTML content using cid: urls. These URLs link to the content ID of another part within the email, rather than being an absolute https:// URL that can be resolved normally.

If one exists, this content ID will be exposed via the contentId property of the Part:

foreach($parts['IMAGE/PNG'] as $image) {
    // Store the file as in the above example:
    file_put_contents($image->name, $image->content);
    // You would then want to store this relationship in your database:    
    echo "{$image->contentId} => {$image->name}\n";
}

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2026-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固