Giter VIP home page Giter VIP logo

mailmimeparser's Introduction

zbateson/mail-mime-parser

Standalone, testable and PSR-compliant mail mime parser alternative to PHP's imap* functions and Pear libraries for reading messages in Internet Message Format (RFC 5322, RFC 2822 and RFC 822).

Build Status Code Coverage Scrutinizer Code Quality Total Downloads Latest Stable Version

The goals of this project are to be:

  • Well written
  • Standards-compliant but forgiving
  • Includable via composer
  • Tested where possible

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 or HHVM. Tested on PHP 5.4, 5.5, 5.6, 7 and 7.1 and HHVM 3.6, 3.9, 3.12, 3.15 and 3.18.

Usage

$mailParser = new \ZBateson\MailMimeParser\MailMimeParser();

$handle = fopen('file.mime', 'r');
$message = $mailParser->parse($handle);         // returns a \ZBateson\MailMimeParser\Message
fclose($handle);
// OR:
$message = $mailParser->parse($rawEmailString);

echo $message->getHeaderValue('from');          // [email protected]
echo $message
    ->getHeader('from')
    ->getPersonName();                          // Person Name
echo $message->getHeaderValue('subject');       // The email's subject

echo $message->getTextContent();                // or getHtmlContent()

$att = $message->getAttachmentPart(0);          // first attachment
echo $att->getHeaderValue('Content-Type');      // e.g. "text/plain"
echo $att->getHeaderParameter(                  // value of "charset" part
    'content-type',
    'charset'
);
echo stream_get_contents(                       // get the attached file
    $att->getContentResourceHandle()            // the file is decoded automatically
);

Documentation

License

BSD licensed - please see license agreement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.