PHPackages                             stevegrunwell/mailto-link-formatter - 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. stevegrunwell/mailto-link-formatter

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

stevegrunwell/mailto-link-formatter
===================================

Formatter for creating complex mailto: links

v1.0.0(8y ago)782.2k↓33.9%2[2 PRs](https://github.com/stevegrunwell/mailto-link-formatter/pulls)MITPHPPHP &gt;=7.0CI failing

Since Apr 16Pushed 3y agoCompare

[ Source](https://github.com/stevegrunwell/mailto-link-formatter)[ Packagist](https://packagist.org/packages/stevegrunwell/mailto-link-formatter)[ RSS](/packages/stevegrunwell-mailto-link-formatter/feed)WikiDiscussions develop Synced 1mo ago

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

Mailto: Link Formatter
======================

[](#mailto-link-formatter)

[![Build Status](https://camo.githubusercontent.com/eefa4be09daa21c4f1ee00b8257ebd3c1c9d75a5eafaeb591b0db5feca830e5c/68747470733a2f2f7472617669732d63692e6f72672f73746576656772756e77656c6c2f6d61696c746f2d6c696e6b2d666f726d61747465722e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/stevegrunwell/mailto-link-formatter)[![Coverage Status](https://camo.githubusercontent.com/e4cfb7881dbf0fedb699a7b0004b78b9b4cc8fc959fc7e8750589daeadce8b9b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73746576656772756e77656c6c2f6d61696c746f2d6c696e6b2d666f726d61747465722f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/stevegrunwell/mailto-link-formatter?branch=develop)[![Packagist](https://camo.githubusercontent.com/12f7fb75e7dac26b9a5ae5bf45d049108dac4ce42dd7d2eb24880c3bddc1665a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746576656772756e77656c6c2f6d61696c746f2d6c696e6b2d666f726d61747465722e737667)](https://packagist.org/packages/stevegrunwell/mailto-link-formatter)

This package defines a `MailTo` class with a simple API for easily generating [RFC 6068-compliant `mailto:` links](https://www.rfc-editor.org/info/rfc2368) in your markup.

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

[](#installation)

You may install the Mailto: Link Formatter package via [Composer](https://getcomposer.org):

```
$ composer require stevegrunwell/mailto-link-formatter
```

If you're already including the Composer-generated autoloader in your project, there's nothing more to do. Otherwise, you'll need to include `src/MailTo.php` into your project.

Usage
-----

[](#usage)

The `MailTo` class collects information about the `mailto:` link, then generates the link itself via its `getLink()` method:

```
use SteveGrunwell\MailToLinkFormatter\MailTo;

$mailto = new MailTo;
$mailto->setRecipients('test@example.com');
$mailto->setHeaders([
    'subject' => 'Hello World!',
    'cc'      => 'foo@example.com',
]);
$mailto->setBody('Some message.');

$mailto->getLink();
# => mailto:test@example.com?subject=Hello%20World!&cc=foo%40example.com&body=Some%20message.
```

If you'd prefer, you may also set properties directly on the `MailTo` object, but be aware that this is merely a convenience method for the corresponding setters and getters:

```
use SteveGrunwell\MailToLinkFormatter\MailTo;

$mailto = new MailTo;

// The same as calling $mailto->setRecipients('test@example.com').
$mailto->recipients = 'test@example.com';

// The same as calling $mailto->getRecipients().
$mailto->recipients
# => ['test@example.com']
```

Properties that are used that do not have corresponding setters/getters (e.g. anything except "recipients", "headers", and "body") will be treated as individual headers, passed through the `setHeader()` and `getHeader()` methods:

```
use SteveGrunwell\MailToLinkFormatter\MailTo;

$mailto = new MailTo;
$mailto->subject = 'Message subject';

$mailto->getHeaders();
# => ['subject' => 'Message subject']
```

### Specifying multiple recipients

[](#specifying-multiple-recipients)

If the `mailto:` link should have multiple recipients, they can be set either by passing an array or a comma-separated string to `setRecipients()`:

```
use SteveGrunwell\MailToLinkFormatter\MailTo;

$mailto = new MailTo;
$mailto->setRecipients([
    'foo@example.com',
    'bar@example.com',
]);

$mailto->getLink();
# => mailto:foo@example.com,bar@example.com
```

The same can be done for headers that might have more than one value, such as `cc` or `bcc`.

### List of headers

[](#list-of-headers)

While [all headers defined in RCF 822](https://tools.ietf.org/html/rfc822) are considered valid, the most common headers used in `mailto:` links are:

 to The intended recipient(s) of the message.  subject The subject line of the message cc One or more email address to "carbon-copy" (CC) on the message. bcc One or more emails to "blind carbon-copy" (BCC) on the message.All headers passed to the package will automatically be made lower-cased.

### Setting arguments via the constructor

[](#setting-arguments-via-the-constructor)

The setters and getters defined by the `MailTo` class are rather conventional, but the class also accepts the most common arguments via its constructor:

```
use SteveGrunwell\MailToLinkFormatter\MailTo;

$mailto = new MailTo('test@example.com', [
    'subject' => 'Hello World!',
    'cc'      => 'foo@example.com',
], 'This is the message body.');

// This is equivalent to:
$mailto = new MailTo;
$mailto->setRecipients('test@example.com');
$mailto->setHeaders([
    'subject' => 'Hello World!',
    'cc'      => 'foo@example.com',
]);
$mailto->setBody('This is the message body.');
```

License
-------

[](#license)

Copyright 2018 Steve Grunwell

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

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Unknown

Total

1

Last Release

2955d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05f4d610f0de13ac1c23825f691fd05f2dd37ae9e8f0483e2dc4f1ca1e2bfb32?d=identicon)[stevegrunwell](/maintainers/stevegrunwell)

---

Top Contributors

[![stevegrunwell](https://avatars.githubusercontent.com/u/233836?v=4)](https://github.com/stevegrunwell "stevegrunwell (30 commits)")

---

Tags

emailformattingmailto

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stevegrunwell-mailto-link-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/stevegrunwell-mailto-link-formatter/health.svg)](https://phpackages.com/packages/stevegrunwell-mailto-link-formatter)
```

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[sendgrid/sendgrid

This library allows you to quickly and easily send emails through Twilio SendGrid using PHP.

1.5k47.5M164](/packages/sendgrid-sendgrid)[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94944.1M110](/packages/pelago-emogrifier)[zbateson/mail-mime-parser

MIME email message parser

54149.2M79](/packages/zbateson-mail-mime-parser)[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48519.5M75](/packages/soundasleep-html2text)[inspheric/nova-email-field

A Laravel Nova email field.

33456.9k1](/packages/inspheric-nova-email-field)

PHPackages © 2026

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