PHPackages                             mathsgod/mht2html - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mathsgod/mht2html

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mathsgod/mht2html
=================

Convert MHT/MHTML files to self-contained HTML with base64-embedded images

v1.0.1(1mo ago)01MITPHPPHP &gt;=8.0

Since Apr 15Pushed 1mo agoCompare

[ Source](https://github.com/mathsgod/mht2html-php)[ Packagist](https://packagist.org/packages/mathsgod/mht2html)[ RSS](/packages/mathsgod-mht2html/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

mht2html-php
============

[](#mht2html-php)

A PHP library to convert MHT/MHTML files into self-contained HTML, with all inline images embedded as base64 data URIs.

Requirements
------------

[](#requirements)

- PHP 8.0+
- [`ext-mailparse`](https://www.php.net/manual/en/book.mailparse.php) (`pecl install mailparse`)

Installation
------------

[](#installation)

```
composer require mathsgod/mht2html
```

Usage
-----

[](#usage)

### Convert from a file

[](#convert-from-a-file)

```
use Mht2Html\Converter;

$converter = new Converter();
$html = $converter->convertFile('/path/to/email.mht');

file_put_contents('output.html', $html);
```

### Convert from a string

[](#convert-from-a-string)

```
use Mht2Html\Converter;

$converter = new Converter();
$mht = file_get_contents('/path/to/email.mht');
$html = $converter->convertString($mht);
```

How it works
------------

[](#how-it-works)

1. Parses the MHT/MHTML file using [`php-mime-mail-parser`](https://github.com/php-mime-mail-parser/php-mime-mail-parser).
2. Extracts the HTML body (Quoted-Printable and charset decoding handled automatically).
3. Collects all inline image attachments and maps each `Content-Location` to a base64 data URI.
4. Replaces every `src="..."` reference in the HTML with the corresponding data URI, producing a fully self-contained HTML file with no external dependencies.

API
---

[](#api)

### `Converter::convertFile(string $path): string`

[](#converterconvertfilestring-path-string)

Reads the MHT file at `$path` and returns self-contained HTML.
Throws `\InvalidArgumentException` if the file cannot be read.

### `Converter::convertString(string $mht): string`

[](#converterconvertstringstring-mht-string)

Accepts raw MHT/MHTML content as a string and returns self-contained HTML.

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance89

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

56d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v1.0.1PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18732337?v=4)[Raymond](/maintainers/mathsgod)[@mathsgod](https://github.com/mathsgod)

---

Top Contributors

[![mathsgod](https://avatars.githubusercontent.com/u/18732337?v=4)](https://github.com/mathsgod "mathsgod (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mathsgod-mht2html/health.svg)

```
[![Health](https://phpackages.com/badges/mathsgod-mht2html/health.svg)](https://phpackages.com/packages/mathsgod-mht2html)
```

###  Alternatives

[abuseio/abuseio

Open Source abusemanagement tool

2281.5k](/packages/abuseio-abuseio)[mikopbx/core

Free PBX system for SMB based on Asterisk

5451.4k](/packages/mikopbx-core)[fabianmichael/kirby-meta

Your all-in-one powerhouse for any SEO and metadata needs imaginable.

7011.3k1](/packages/fabianmichael-kirby-meta)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
