PHPackages                             vphantom/email - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. vphantom/email

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

vphantom/email
==============

Create/send multipart MIME messages

v1.0.2(9y ago)01931MITPHPPHP &gt;=7.0CI failing

Since Mar 1Pushed 9y ago1 watchersCompare

[ Source](https://github.com/vphantom/php-email)[ Packagist](https://packagist.org/packages/vphantom/email)[ RSS](/packages/vphantom-email/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (1)

Email
=====

[](#email)

![license](https://camo.githubusercontent.com/718f6c388be2e951e0b4272f0e8bde9035498e577f1c87bc97e89d873f416261/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f767068616e746f6d2f7068702d656d61696c2e7376673f7374796c653d706c6173746963) ![GitHub release](https://camo.githubusercontent.com/c02a175eaf011363d0d389efc609267d783a0e2b2ff6bfabddcd2acf60090012/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f767068616e746f6d2f7068702d656d61696c2e7376673f7374796c653d706c6173746963) [![Build Status](https://camo.githubusercontent.com/9a0abec7195691bc2fab92c353e476654595f2e9f1c32245fd3f254b1815873d/68747470733a2f2f7472617669732d63692e6f72672f767068616e746f6d2f7068702d656d61696c2e7376673f6272616e63683d76312e302e32)](https://travis-ci.org/vphantom/php-email) [![Coverage Status](https://camo.githubusercontent.com/3f6bb9db4c06ea3ff447f722e838e2c8a17c2fdeaa730e90473d885153ffefc9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f767068616e746f6d2f7068702d656d61696c2f62616467652e7376673f6272616e63683d76312e302e32)](https://coveralls.io/github/vphantom/php-email?branch=v1.0.2)

Create/send multipart MIME messages

Facilitates the creation of MIME compatible messages. It has useful features like easy creation of alternative bodies (i.e. plain+html) and multiple file attachments. It is *not* a complete implementation, but it is very small which suits my needs.

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

[](#installation)

```
$ composer require vphantom/email
```

Usage
-----

[](#usage)

Basically, you instantiate the `Email` class, set a few headers, add some content parts (at least one) and either build to a string using `$msg->build()` or send by piping through `sendmail` with `$msg->send()`.

`class Email`
-------------

[](#class-email)

Create/send multipart MIME messages.

Example:

```
require_once 'email.php';
mb_internal_encoding('UTF-8');
$msg = new Email();
$msg->charset = 'UTF-8';
$msg->to = "Someone ";
$msg->from = "Myself ";
$msg->subject = "Friendly reminder service";
$msg->addText("Hello Someone,\n\nThis is your friendly reminder.\n");
$msg->addFile('image/png', '/tmp/test-file.png', 'reminder.png');
$msg->send();

```

### `public function __set($name, $value)`

[](#public-function-__setname-value)

Property overloading.

To define any header, set a property of the same name. If the header name contains dashes, use underscores instead and they will be converted to dashes. For example:

```
$msg = new Email();
$msg->X_Mailer_Info = "My Custom Mailer v0.15";

```

**Parameters:**

- `$name` — string — Name which will have underscores changed to dashes
- `$value` — string — Contents of the header

**Returns:** null

### `public function __construct()`

[](#public-function-__construct)

Constructor

**Returns:** `object` — Email instance

### `public function addData($type, $displayname, $data)`

[](#public-function-adddatatype-displayname-data)

Add a raw data part to message.

Netiquette: you should add text and HTML parts before any binary file attachments.

**Parameters:**

- `$type` — string — MIME type of the attachment (i.e. "text/plain")
- `$displayname` — string — File name to suggest to user
- `$data` — mixed — Actual raw data to attach

**Returns:** null

### `public function addFile($filepath, $displayname, $mimetype = null)`

[](#public-function-addfilefilepath-displayname-mimetype--null)

Attach a file part to message.

Netiquette: you should add binary files after inline text and HTML parts.

Note that the MIME type is automatically detected from the file itself if not specified.

**Parameters:**

- `$filepath` — string — Path on local file system
- `$displayname` — string — File name to suggest to user
- `$mimetype` — string|null — (Optional) MIME Type

**Returns:** null

### `public function addText($text)`

[](#public-function-addtexttext)

Attach plain text part to message.

**Parameters:**

- `$text` — string — Content to attach

**Returns:** null

### `public function addHTML($html)`

[](#public-function-addhtmlhtml)

Attach HTML part to message.

**Parameters:**

- `$html` — string — Content to attach

**Returns:** null

### `public function addTextHTML($text, $html)`

[](#public-function-addtexthtmltext-html)

Attach a pair of text and HTML equivalents to message.

This implements the "multipart/alternative" type so viewers can expect the text and HTML to represent the same content.

**Parameters:**

- `$text` — string — The plain text content
- `$html` — string — The HTML equivalent content

**Returns:** null

### `public function build($skipTS = false)`

[](#public-function-buildskipts--false)

Build message to a string.

**Caveat:** If you intend to use PHP's `mail()`, you will need to split headers from the body yourself since PHP needs headers separately, and use the `$skipTS` argument to extract "To" and "Subject" from the headers. Something like this:

```
$parts = preg_split('/\r?\n\r?\n/', $msg->build(true), 2);
mail($msg->getTo(), $msg->getSubject(), $parts[1], $parts[0]);

```

**Parameters:**

- `$skipTS` — bool — Skip "To" and "Subject" headers.

**Returns:** `string` — The entire message ready to send (i.e. via `sendmail`)

### `public function send()`

[](#public-function-send)

Build and immediately send message.

Note that you can modify some headers and call `build()` or `send()` again on the current message. This can be handy for mailing lists where only the destination changes (and where using the "Bcc" field isn't appropriate, that is.)

Internally, this uses PHP's `popen()` to invoke your PHP configuration's "sendmail\_path" directly. This avoids the extra overhead and formatting limitations of PHP's built-in `mail()`.

**Returns:** `mixed` — False if the pipe couldn't be opened, the termination status of the sendmail process otherwise.

MIT License
-----------

[](#mit-license)

Copyright (c) 2008-2017 Stéphane Lavergne

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~1 days

Total

3

Last Release

3359d ago

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

v1.0.1PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/583df83dd751c2f71dc868107eb206fdcde7e0cdc1569ca052f02eaed7e03977?d=identicon)[vphantom](/maintainers/vphantom)

---

Top Contributors

[![vphantom](https://avatars.githubusercontent.com/u/3063161?v=4)](https://github.com/vphantom "vphantom (11 commits)")

---

Tags

email-senderphpphp-libraryrfc822

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vphantom-email/health.svg)

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

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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