Download the PHP package lasso/mail-parser-bundle without Composer

On this page you can find all versions of the php package lasso/mail-parser-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mail-parser-bundle

Lasso Mail Parser Build Status

For when you want easy access to an email's content. The Zend Framework has classes to parse emails, but they can be a bit clunky to use. For example, emails are split into parts, and you have to loop over all the parts in an email (which itself is treated as a part) to access the content.

What it does

The Lasso Mail Parser offers a simple way to get either html or text content from an email, discarding file attachments. Should both html and text parts be given, html is preferred.

How it works

An email is parsed with the Zend mail parser. It's parts are then recursively grouped by content type, such as 'text/plain' or 'text/html'. If any html or text parts are found, they are concatenated and the result returned. If no such parts are found, null is returned.

The concatenation string is determined by a call to a user-defined function, which makes flexible concatenation possible.

Usage

As this is a symfony bundle, you can add this repository to your composer.json file:

https://packagist.org/packages/lasso/mail-parser-bundle

Then request the parser like this:

$parser = $container->get('lasso_mail_parser.parser');

Of course, it can be used with dependency injection too by adding it to your services.xml as a parameter.

Once you have a parser instance, parse the raw email source like this:

$parser->parse(YOUR-EMAIL-BODY);

You can then use

$emailAddresses = $parser->getAllEmailAddresses();

to extract email address from the email. You can restrict the fields used for extraction by passing in an array with the field names you wish to use:

// Only retrieve recipients
$receiverEmailAddresses = $parser->getAllEmailAddress(['to', 'cc', 'bcc']);

Use

$content = $parser->getPrimaryContent();

to get the main content. This will be html if html is present, else it will be plain text. You can pass in a custom glue function:

$glue = function($contentType) {
    switch ($contentType) {
        case 'text/plain':
            return "\n====\n";

        case 'text/html':
            return '<hr />';
    }

    return '';
}

$content = $parser->getPrimaryContent($glue);

Now all html parts will be concatenated with hr-tags, and all text parts will be concatenated with newlines and '===='.

If you are processing emails send via envelope journaling (e.g. from Office365), you can access the enveloped email via

$parser->getEnvelopedEmail();

This will return a normal part, and you can access content/headers on it. To check if an email has an enveloped email as an attachment, you can use

$parser->hasEnvelopedEmail();

All versions of mail-parser-bundle with dependencies

PHP Build Version
Package Version
Requires zendframework/zend-mail Version 2.5.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lasso/mail-parser-bundle contains the following files

Loading the files please wait ...