cosmira / envelope
An elegant PHP library for parsing and extracting structured email contents, including attachments and metadata.
Requires
- php: ^8.2
- illuminate/collections: ^11.0 || ^12.0
- zbateson/mail-mime-parser: ^3.0.3
Requires (Dev)
- laravel/pint: ^1.17
- phpunit/phpunit: ^11.5
- symfony/var-dumper: ^7.1
- vimeo/psalm: ^6.8
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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; }