Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vaibhavpandeyvpz/phemail
MIME parser written in pure PHP for parsing raw emails (.eml) files.
https://github.com/vaibhavpandeyvpz/phemail
Last synced: 4 days ago
JSON representation
MIME parser written in pure PHP for parsing raw emails (.eml) files.
- Host: GitHub
- URL: https://github.com/vaibhavpandeyvpz/phemail
- Owner: vaibhavpandeyvpz
- License: mit
- Created: 2016-12-07T03:24:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-14T06:52:17.000Z (12 months ago)
- Last Synced: 2024-05-03T03:53:19.109Z (6 months ago)
- Language: PHP
- Homepage: http://vaibhavpandeyvpz.github.io/phemail
- Size: 61.5 KB
- Stars: 31
- Watchers: 2
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# vaibhavpandeyvpz/phemail
MIME parser written in pure [PHP](http://www.php.net/) for parsing raw emails (.eml) files.[![Latest Version](https://img.shields.io/github/release/vaibhavpandeyvpz/phemail.svg?style=flat-square)](https://github.com/vaibhavpandeyvpz/phemail/releases)
[![Coverage Status](https://coveralls.io/repos/github/vaibhavpandeyvpz/phemail/badge.svg?branch=master)](https://coveralls.io/github/vaibhavpandeyvpz/phemail?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/vaibhavpandeyvpz/phemail.svg?style=flat-square)](https://packagist.org/packages/vaibhavpandeyvpz/phemail)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)Install
---
```bash
composer require vaibhavpandeyvpz/phemail
```Usage
---
Suppose this is your email file named `sample.eml`:```eml
Mime-Version: 1.0
Message-Id: <[email protected]>
From: Vaibhav Pandey
To: Vaibhav Pandey
Subject: Testing simple email
Date: Sat, 22 Nov 2008 15:04:59 +1100
Content-Type: text/plain; charset=US-ASCII; format=flowed
Content-Transfer-Encoding: 7bitThis is simple as f*** plain text email message.
Regards,
Vaibhav Pandey
```You can read & parse it as follows:
```php
parse(__DIR__ . '/sample.eml');echo $message->getHeaderValue('subject');
# outputs 'Testing simple email'echo $message->getHeaderValue('date');
# outputs 'Sat, 22 Nov 2008 15:04:59 +1100'echo $message->getHeaderValue('content-type');
# outputs 'text/plain'echo $message->getHeaderAttribute('content-type', 'charset');
# outputs 'US-ASCII'echo $message->getContents();
/**
* @desc To extract emails from headers, you could use any RFC 822
* internet address parser e.g., pear/mail.
*/
$addresses = (new Mail_RFC822())->parseAddressList($message->getHeaderValue('to'));
foreach ($addresses as $address) {
echo 'Name: ', $address->personal, '
', 'Email: ', $address->mailbox, '@', $address->host;
}
```License
------
See [LICENSE.md](https://github.com/vaibhavpandeyvpz/phemail/blob/master/LICENSE.md) file.