PHP code example of cosmira / envelope

1. Go to this page and download the library: Download cosmira/envelope library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cosmira / envelope example snippets


use Cosmira\Envelope\Envelope;

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

$mail = new Envelope($content);

$mail->from();
// "[email protected]"

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

$mail->to();
// Collection: ['[email protected]' => 'Jane Doe']

$mail->cc();
// Collection: ['[email protected]' => 'Team Assistant']

$mail->bcc();
// Collection: ['[email protected]' => 'Confidential']

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

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

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

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

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