opcodesio/mail-parser

Parse emails without the mailparse extension

Maintainers

👁 arukomp

Package info

github.com/opcodesio/mail-parser

pkg:composer/opcodesio/mail-parser

Statistics

Installs: 8 482 720

Dependents: 9

Suggesters: 0

Stars: 22

Open Issues: 1

v0.2.4 2026-06-11 08:50 UTC

Requires

  • php: ^8.0

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 7151e4183288e46d911a76803c5545a1c8822226

  • Arunas Skirius <arukomp.woop@gmail.com>

mailphpemailarukompasopcodesioemail parser

This package is auto-updated.

Last update: 2026-06-11 08:52:22 UTC


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(); // `Date:` header as DateTime object
$message->getSize(); // Email size in bytes

$message->getParts(); // array of \Opcodes\MailParser\MessagePart, which can be html parts, text parts, attachments, etc.
$message->getHtmlPart(); // \Opcodes\MailParser\MessagePart containing the HTML body
$message->getTextPart(); // \Opcodes\MailParser\MessagePart containing the Text body
$message->getAttachments(); // 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.