定制 opcodesio/mail-parser 二次开发

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

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

opcodesio/mail-parser

最新稳定版本:v0.2.1

Composer 安装命令:

composer require opcodesio/mail-parser

包简介

Parse emails without the mailparse extension

README 文档

README

Mail Parser for PHP
Simple, fast, no extensions required

Features | Installation | Credits

Packagist Packagist PHP from Packagist

Features

OPcodes's Mail Parser has a very simple API to parse emails and their MIME contents. Unlike many other parsers out there, this package does not require the mailparse PHP extension.

Has not been fully tested against RFC 5322.

Get Started

Requirements

  • PHP 8.0+

Installation

To install the package via composer, Run:

composer require opcodesio/mail-parser

Usage

use Opcodes\MailParser\Message;

// Parse a message from a string
$message = Message::fromString('...');
// Or from a file location (accessible with file_get_contents())
$message = Message::fromFile('/path/to/email.eml');

$message->getHeaders();                 // get all headers
$message->getHeader('Content-Type');    // 'multipart/mixed; boundary="----=_Part_1_1234567890"'
$message->getFrom();                    // 'Arunas <arunas@example.com>
$message->getTo();                      // 'John Doe <johndoe@example.com>
$message->getSubject();                 // 'Subject line'
$message->getDate();                    // DateTime object when the email was sent
$message->getSize();                    // Email size in bytes

$message->getParts();       // Returns an array of \Opcodes\MailParser\MessagePart, which can be html parts, text parts, attachments, etc.
$message->getHtmlPart();    // Returns the \Opcodes\MailParser\MessagePart containing the HTML body
$message->getTextPart();    // Returns the \Opcodes\MailParser\MessagePart containing the Text body
$message->getAttachments(); // Returns an array of \Opcodes\MailParser\MessagePart that represent attachments

$messagePart = $message->getParts()[0];

$messagePart->getHeaders();                 // array of all headers for this message part
$messagePart->getHeader('Content-Type');    // value of a particular header
$messagePart->getContentType();             // 'text/html; charset="utf-8"'
$messagePart->getContent();                 // '<html><body>....'
$messagePart->getSize();                    // 312
$messagePart->getFilename();                // name of the file, in case this is an attachment part

Contributing

A guide for contributing is in progress...

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 21
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04