PHPackages                             initphp/mailer - 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. initphp/mailer

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

initphp/mailer
==============

Send e-mail through the native mail() function, a sendmail binary or SMTP with attachments, inline images and MIME multipart bodies.

2.0.0(3w ago)168MITPHPPHP &gt;=8.1CI passing

Since Mar 15Pushed 3w ago1 watchersCompare

[ Source](https://github.com/InitPHP/Mailer)[ Packagist](https://packagist.org/packages/initphp/mailer)[ RSS](/packages/initphp-mailer/feed)WikiDiscussions main Synced today

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

InitPHP Mailer
==============

[](#initphp-mailer)

A small, dependency-free PHP mailer. Compose a message with a fluent API and send it through PHP's native `mail()`, a local `sendmail` binary, or SMTP — with attachments, inline images, HTML + plain-text multipart bodies and RFC-compliant header encoding.

[![Latest Stable Version](https://camo.githubusercontent.com/a031c47631a0ebe7aff9992e77c7b7e7e40a9a2df53b3de552c59cbf4a6d1355/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6d61696c65722f76)](https://packagist.org/packages/initphp/mailer) [![Total Downloads](https://camo.githubusercontent.com/781531fac34172f6a27557af931ffa680c0f622f5836badce60acfded859d8fb/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6d61696c65722f646f776e6c6f616473)](https://packagist.org/packages/initphp/mailer) [![License](https://camo.githubusercontent.com/61e97d72e239fad89588aa307c88c65249f2f586a6b6875ec421d39f171d1b7f/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6d61696c65722f6c6963656e7365)](https://packagist.org/packages/initphp/mailer) [![PHP Version Require](https://camo.githubusercontent.com/9437f7b716a7efeb70d24f9c0dce4dfd5903a055a518fc79f38da6d467cac680/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f6d61696c65722f726571756972652f706870)](https://packagist.org/packages/initphp/mailer)

> **Upgrading from 1.x?** Version 2.0 keeps the same fluent API but raises the PHP requirement, encapsulates state and replaces `bool` return values with exceptions. See [UPGRADE-2.0.md](UPGRADE-2.0.md).

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

[](#requirements)

- PHP 8.1 or higher
- ext-mbstring, ext-iconv, ext-fileinfo

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

[](#installation)

```
composer require initphp/mailer
```

Quick start
-----------

[](#quick-start)

### SMTP

[](#smtp)

```
use InitPHP\Mailer\Mailer;
use InitPHP\Mailer\Exception\MailerException;

$mailer = Mailer::newInstance([
    'protocol'   => 'smtp',
    'SMTPHost'   => 'smtp.example.com',
    'SMTPUser'   => 'you@example.com',
    'SMTPPass'   => 'your-password',
    'SMTPPort'   => 587,
    'SMTPCrypto' => 'tls',
]);

try {
    $mailer->setFrom('you@example.com', 'Your Name')
        ->setTo('recipient@example.com')
        ->setSubject('Hello from InitPHP Mailer')
        ->setMessage('This is a plain-text message.')
        ->send();
} catch (MailerException $e) {
    // $e->getMessage(); for SMTP failures $e->getCode() holds the reply code.
}
```

### Native `mail()`

[](#native-mail)

```
$mailer = Mailer::newInstance(); // protocol defaults to "mail"

$mailer->setFrom('you@example.com', 'Your Name')
    ->setTo('recipient@example.com')
    ->setSubject('Hello')
    ->setMessage('Plain-text body')
    ->send();
```

### HTML with a plain-text alternative

[](#html-with-a-plain-text-alternative)

```
$mailer->setMailType('html')
    ->setFrom('you@example.com', 'Your Name')
    ->setTo('recipient@example.com')
    ->setSubject('Newsletter')
    ->setMessage('HelloThis is an HTML message.')
    ->setAltMessage('Hello — this is the plain-text fallback.')
    ->send();
```

### Attachments and inline images

[](#attachments-and-inline-images)

```
$mailer->setMailType('html')
    ->setFrom('you@example.com')
    ->setTo('recipient@example.com')
    ->setSubject('Invoice')
    ->attach('/path/to/invoice.pdf');             // a file on disk

// In-memory / generated content (no temp file needed):
$pdf = $generator->render();
$mailer->attachContent($pdf, 'invoice.pdf', 'attachment', 'application/pdf');

// Inline image referenced from the HTML with cid:
$mailer->attach('/path/to/logo.png', 'inline');
$cid = $mailer->setAttachmentCID('/path/to/logo.png');
$mailer->setMessage(' Welcome!')
    ->send();
```

Error handling
--------------

[](#error-handling)

`send()` returns `void` and throws on failure. Invalid input is rejected as soon as it is supplied (fail-fast), not deferred to `send()`.

ExceptionWhen`InvalidAddressException`A sender/recipient address fails validation.`ConfigurationException`A required value is missing (no sender, no recipient, empty SMTP host).`AttachmentException`An attachment cannot be read or its type detected.`TransportException`Delivery failed (the SMTP reply code is in `getCode()`).All extend `InitPHP\Mailer\Exception\MailerException`, so a single `catch` can handle any failure.

Facade
------

[](#facade)

For quick, one-off usage there is a static facade backed by a shared instance:

```
use InitPHP\Mailer\Facade\Mailer;

Mailer::setFrom('you@example.com')
    ->setTo('recipient@example.com')
    ->setSubject('Hi')
    ->setMessage('Body')
    ->send();
```

To configure the shared instance, build a `Mailer` and register it:

```
use InitPHP\Mailer\Mailer as MailerInstance;
use InitPHP\Mailer\Facade\Mailer;

Mailer::setInstance(MailerInstance::newInstance(['protocol' => 'smtp', /* … */]));
```

Documentation
-------------

[](#documentation)

Full developer documentation lives in [`docs/`](docs/README.md):

- [Getting started](docs/getting-started.md)
- [Configuration](docs/configuration.md)
- [Sending mail](docs/sending-mail.md)
- [Attachments](docs/attachments.md)
- [SMTP transport](docs/smtp-transport.md)
- [Encoding &amp; headers](docs/encoding-and-headers.md)
- [Exceptions](docs/exceptions.md)
- [Facade](docs/facade.md)

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome on the [issue tracker](https://github.com/InitPHP/Mailer/issues). New code should come with tests; run the full check bundle before opening a PR:

```
composer ci   # php-cs-fixer (dry-run) + phpstan + phpunit
```

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Released under the [MIT License](./LICENSE). Copyright © 2022 InitPHP.

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

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

Total

4

Last Release

24d ago

Major Versions

1.x-dev → 2.0.02026-06-10

PHP version history (2 changes)1.0PHP &gt;=7.4

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Top Contributors

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

---

Tags

attachmentemailemail-senderinitphpmailmailermimephpphp-mailersendmailsmtpmailmimeemailmailerattachmentsmtpsendmailinitphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/initphp-mailer/health.svg)

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

###  Alternatives

[nette/mail

📧 Nette Mail: A handy library for creating and sending emails in PHP.

54010.2M282](/packages/nette-mail)[zbateson/mail-mime-parser

MIME email message parser

54753.3M91](/packages/zbateson-mail-mime-parser)[aplus/email

Aplus Framework Email Library

2561.6M3](/packages/aplus-email)[mlocati/spf-lib

Parse, build and validate SPF (Sender Policy Framework) DNS records

68955.6k4](/packages/mlocati-spf-lib)[pear/net_smtp

An implementation of the SMTP protocol

263.2M23](/packages/pear-net-smtp)[voku/bounce-mail-handler

Bounce Mail Handler

50246.0k2](/packages/voku-bounce-mail-handler)

PHPackages © 2026

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