-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[![Build Status](https://travis-ci.org/zbateson/MailMimeParser.svg?branch=master)](https://travis-ci.org/zbateson/MailMimeParser) | ||
|
||
# zbateson/mail-mime-parser | ||
|
||
Standalone, testable and PSR-compliant mail mime parser alternative to PHP's | ||
imap* functions and pear libraries. | ||
|
||
[![Build Status](https://travis-ci.org/zbateson/MailMimeParser.svg?branch=master)](https://travis-ci.org/zbateson/MailMimeParser) | ||
|
||
The goals of this project are to be: | ||
|
||
* Well written | ||
|
@@ -17,3 +17,38 @@ To include it for use in your project, please install via composer: | |
``` | ||
composer require zbateson/mail-mime-parser | ||
``` | ||
|
||
## Requirements | ||
|
||
MailMimeParser requires PHP 5.4 or newer. | ||
|
||
## Usage | ||
|
||
```php | ||
$mailParser = new ZBateson\MailMimeParser(); | ||
|
||
$handle = fopen('file.mime', 'r'); | ||
$message = $mailParser->parse($handle); // returns a ZBateson\Message | ||
fclose($handle); | ||
|
||
echo $message->getHeaderValue('from'); // [email protected] | ||
echo $message->getHeader('from')->getName(); // Person Name | ||
echo $message->getHeaderValue('subject'); // The email's subject | ||
|
||
$res = $message->getTextStream(); // or getHtmlStream | ||
echo stream_get_contents($res); | ||
|
||
$att = $message->getAttachmentPart(0); // first attachment | ||
echo $att->getHeaderValue('Content-Type'); // text/plain for instance | ||
echo $att->getHeaderParameter( // value of "charset" part | ||
'content-type', | ||
'charset' | ||
); | ||
echo stream_get_contents( | ||
$att->getContentRersourceHandle() | ||
); | ||
``` | ||
|
||
## License | ||
|
||
BSD licensed - please see [license agreement](https://github.com/zbateson/MailMimeParser/blob/master/LICENSE). |