cosmira/envelope

An elegant PHP library for parsing and extracting structured email contents, including attachments and metadata.

Installs: 58

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/cosmira/envelope

0.0.1 2025-07-03 13:54 UTC

This package is not auto-updated.

Last update: 2025-10-07 21:17:48 UTC


README

Tests Quality Assurance Coding Guidelines

Introduction

An elegant PHP library for parsing and extracting structured email contents, including attachments, headers, and metadata. Built on top of the powerful ZBateson\MailMimeParser package, it offers a clean and intuitive API that simplifies working with email data.

Installation

You can install the package via Composer:

composer require cosmira/envelope

Usage

To use the Envelope class, instantiate it with raw email content.

use Cosmira\Envelope\Envelope;

$content = file_get_contents('path_to_email_file.eml');

$mail = new Envelope($content);

API Reference

from()

Get the sender’s email address.

$mail->from();
// "john@example.com"

fromName()

Get the sender’s display name.

$mail->fromName();
// "John Doe"

to()

Get the primary recipients as an array of email => name pairs.

$mail->to();
// Collection: ['jane@example.com' => 'Jane Doe']

cc()

Get the CC recipients as an array of email => name pairs.

$mail->cc();
// Collection: ['assistant@example.com' => 'Team Assistant']

bcc()

Get the BCC recipients as an array of email => name pairs.

$mail->bcc();
// Collection: ['hidden@example.com' => 'Confidential']

subject()

Get the subject line of the email.

$mail->subject();
// "Project Kickoff Meeting"

date()

Get the date the email was sent as a DateTime object.

$mail->date()->format('Y-m-d H:i:s');
// "2025-09-11 10:32:00"

text()

Get the plain text content of the email.

$mail->text();
// "Hello team, the meeting is scheduled for tomorrow..."

html()

Get the HTML content of the email.

$mail->html();
// "<p>Hello team,<br>The meeting is scheduled for tomorrow...</p>"

attachments()

Get all attachments as an array, with each item containing name, mime, and content.

$mail->attachments()->each(function ($file) {
    echo 'Filename:  ' . $file['name'] . PHP_EOL;
    echo 'MIME Type: ' . $file['mime'] . PHP_EOL;
    echo 'Content:   ' . $file['content'] . PHP_EOL;
}