PHPackages                             atk14/sendmail - 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. atk14/sendmail

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

atk14/sendmail
==============

A powerful replacement for PHP's mail() function with MIME support, attachments, and a custom transport hook

v1.0.5(3w ago)03.7k2MITHTMLPHP &gt;=5.6.0CI passing

Since Jul 30Pushed 3w ago2 watchersCompare

[ Source](https://github.com/atk14/Sendmail)[ Packagist](https://packagist.org/packages/atk14/sendmail)[ Docs](https://github.com/atk14/Sendmail)[ RSS](/packages/atk14-sendmail/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (7)Used By (2)

Sendmail
========

[](#sendmail)

[![Tests](https://github.com/atk14/Sendmail/actions/workflows/tests.yml/badge.svg)](https://github.com/atk14/Sendmail/actions/workflows/tests.yml)

Sendmail is a replacement for function mail() in PHP.

Basic usage
-----------

[](#basic-usage)

Function sendmail() can be called the same way like built-in function mail().

```
sendmail(string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]])

```

So in a legacy project every mail() occurrence can be replaced with sendmail().

```
sendmail("john@doe.com","Thank you for registration","Dear John\n\nthank you for your registration...");

```

Sendmail can also be called with associative array which offers more options.

```
$mail_ar = sendmail([
  "from" => "info@snakeoil.com",
  "from_name" => "Snake Oil",
  // or "from" => "Snake Oil ",

  // "return_path" => "info@snakeoil.com",

  // "reply_to" => "reply@snakeoil.com",
  // "reply_to_name" => "Snake Oil",

  "to" => "John Doe ",
  // "cc" => "",
  // "bcc" => "",

  "subject" => "Thank you for registration",
  "body" => "Dear John\n\nthank you for registration...",
  // "mime_type" => "text/plain",
  // "charset" => "UTF-8",
  // "transfer_encoding" => "quoted-printable",

  "attachments" => [
    [
      "body" => file_get_contents("/path/to/file"),
      "filename" => "confirmation.pdf",
      "mime_type" => "application/pdf",
    ],[
      "body" => file_get_contents("/path/to/another/file"),
      "filename" => "id_card.png",
      "mime_type" => "image/png"
    ]
  ],

  // "build_message_only" => false,
]);

```

Returned value is an associative array, which contains the complete assembled message and also a status "accepted\_for\_delivery" (`true` on success, `false` on failure, or `null` when sending is suppressed by the environment). The array can be used as a parameter for another sendmail() call.

```
$mail_ar = sendmail([
  ...
  "build_message_only" => true
])

$mail_ar["to"] = "john@doe.com";
sendmail($mail_ar);

$mail_ar["to"] = "samantha@doe.com";
sendmail($mail_ar);

// and so on

```

Sending HTML emails with images
-------------------------------

[](#sending-html-emails-with-images)

For sending HTML emails there is another function sendhtmlmail().

```
$mail_ar = sendhtmlmail([
  "from" => "info@snakeoil.com",
  "to" => "john@doe.com",

  "subject" => "Sample HTML email",
  "plain" => "Plain text version",
  "html" => "Html version",

  "images" => [
    [
      "filename" => "sea.gif",
      "content" => $binary_content,
      "cid" => "c8792dkQW",
    ],
    [
      "filename" => "mountain.jpg",
      "content" => $binary_content_2,
      "cid" => "tytdk2392981",
    ]
  ]
]);

```

Configuration constants
-----------------------

[](#configuration-constants)

There are several constants that affect the default behavior of Sendmail. Please note that they must be defined before Sendmail is being loaded.

```
define("SENDMAIL_DEFAULT_FROM","info@snakeoil.com");
define("SENDMAIL_DEFAULT_FROM_NAME","Snake Oil");
define("SENDMAIL_DEFAULT_BODY_CHARSET","UTF-8");
define("SENDMAIL_DEFAULT_BODY_MIME_TYPE","text/plain");
define("SENDMAIL_BODY_AUTO_PREFIX",""); // "This is a testing message\nIgnore it. Do not reply!\n\n\n"
define("SENDMAIL_USE_TESTING_ADDRESS_TO","");
define("SENDMAIL_DO_NOT_SEND_MAILS",((defined("DEVELOPMENT") && DEVELOPMENT) || (defined("TEST") && TEST)));
define("SENDMAIL_EMPTY_TO_REPLACE","missing.email@snakeoil.com");
define("SENDMAIL_DEFAULT_TRANSFER_ENCODING","8bit"); // "8bit" or "quoted-printable"
define("SENDMAIL_MAIL_ADDITIONAL_PARAMETERS","-fbounce@snakeoil.com");
define("SENDMAIL_BCC_TO","sent.emails@snakeoil.com");

```

Custom sending hook
-------------------

[](#custom-sending-hook)

If a function `sendmail_hook_send()` is defined, it is called instead of the built-in `mail()`. This allows custom transports, logging, or queueing.

```
function sendmail_hook_send(array $mail_ar, array $orig_params): array {
  // $mail_ar contains: to, from, subject, headers, body, accepted_for_delivery, ...
  // $orig_params contains the original parameters passed to sendmail()

  // custom sending logic here, e.g.:
  MyMailQueue::push($mail_ar);

  $mail_ar["accepted_for_delivery"] = true;
  return $mail_ar;
}

```

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

[](#installation)

Just use the Composer:

```
composer require atk14/sendmail

```

License
-------

[](#license)

Sendmail is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance94

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

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

Recently: every ~705 days

Total

6

Last Release

25d ago

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v1.0.2PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6304dffbd91d7a978f98632b0e4e30d662dcdb691daadb1388a58984e98faf5c?d=identicon)[yarri](/maintainers/yarri)

---

Top Contributors

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

---

Tags

mailmimeemailsmtpsendmailattachments

### Embed Badge

![Health badge](/badges/atk14-sendmail/health.svg)

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

###  Alternatives

[zbateson/mail-mime-parser

MIME email message parser

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

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

5389.8M246](/packages/nette-mail)[mlocati/spf-lib

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

67867.9k2](/packages/mlocati-spf-lib)[pear/net_smtp

An implementation of the SMTP protocol

263.0M16](/packages/pear-net-smtp)[thefox/smtpd

SMTP server (library) written in pure PHP.

1302.4k1](/packages/thefox-smtpd)[bashkarev/email

Faster MIME Mail Parser could be used to parse emails in MIME format.

208.8k](/packages/bashkarev-email)

PHPackages © 2026

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