horde/mime

MIME library

v3.0.0 2026-06-26 00:00 UTC

Requires

Requires (Dev)

Suggests

Provides

None

Conflicts

None

Replaces

None

LGPL-2.1-only 7afa488b6dd7169abe938925c52636720675fdb7

  • Chuck Hagenbuch <chuck.woop@horde.org>
  • Michael Slusarz <slusarz.woop@horde.org>

mailheaders


README

MIME message handling library for PHP 8.2+.

Provides immutable value objects for building, parsing and rendering RFC 2822/2045 MIME messages.

Installation

composer require horde/mime

Quick Start

use Horde\Mime\MessageBuilder;
use Horde\Mime\MessageRenderer;
use Horde\Mime\MimeParser;
use Horde\Mime\PartBuilder;

// Compose a message
$builder = new MessageBuilder();
$builder->setFrom('sender@example.com')
 ->setTo('rcpt@example.com')
 ->setSubject('Hello')
 ->setBody('Plain text body', flowed: true)
 ->addAttachment('/path/to/file.pdf');

$composed = $builder->build();
$raw = MessageRenderer::render($composed->part, $composed->headers);

// Parse a message
$part = MimeParser::parse($rawMessage);
echo $part->fullType(); // e.g. "multipart/mixed"
echo $part->children[0]->body; // first child's decoded body

// Build parts directly
$part = PartBuilder::text('Hello world')->build();
$html = PartBuilder::html('<p>Hello</p>')->build();
$attachment = PartBuilder::attachment($data, 'report.pdf', 'application/pdf')->build();

Documentation

License

LGPL 2.1 - see LICENSE for details.