PHPackages                             lucinda/mailing - 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. lucinda/mailing

ActiveLibrary

lucinda/mailing
===============

Very light weight PHP API for email sending and digital signing covering most important parts of RFC-4021 &amp; RFC-6376 specs

v3.0.1(3y ago)09.0k1[1 issues](https://github.com/aherne/php-mailing-api/issues)MITPHPPHP ^8.1

Since Jul 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/aherne/php-mailing-api)[ Packagist](https://packagist.org/packages/lucinda/mailing)[ Docs](https://github.com/aherne/php-mailing-api)[ RSS](/packages/lucinda-mailing/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (13)Used By (0)

PHP Mailing API
===============

[](#php-mailing-api)

Very lightweight PHP API covering most important parts of [RFC-4021](https://tools.ietf.org/html/rfc4021), the worldwide standard at this moment for email sending, along with [RFC-6376](https://tools.ietf.org/html/rfc6376) for digital signatures.

API requires PHP 8.1+ and comes with just four classes, all belonging to Lucinda\\Mail namespace:

- [Address](https://github.com/aherne/php-mailing-api/blob/master/src/Address.php): encapsulates an email address, composed by value of email and name of user associated with it
- [DKIM](https://github.com/aherne/php-mailing-api/blob/master/src/DKIM.php): creates a DKIM-Signature header using on a heavily refactored version of [php-mail-signature](https://github.com/louisameline/php-mail-signature) classes
- [Exception](https://github.com/aherne/php-mailing-api/blob/master/src/Exception.php): encapsulates any logical error that prevents email from being sent
- [Message](https://github.com/aherne/php-mailing-api/blob/master/src/Message.php): encapsulates an email message

The entire logic of email message is encapsulated by class **[Message](https://github.com/aherne/php-mailing-api/blob/master/src/Message.php)** via following public methods:

MethodDescription[\_\_construct](#__construct)Constructs an email message by subject and body[addAttachment](#addAttachment)Adds an attachment to message body[setFrom](#setFrom)Sets message sender's address, as seen in recipients' mail boxes[setSender](#setSender)Sets message sender's address, as seen by recipients' mail server[setReplyTo](#setReplyTo)Adds address message receiver should reply to[addTo](#addTo)Adds address to send mail to (**mandatory**)[addBCC](#addBCC)Adds address to discreetly send a copy of message to (invisible to others)[addCC](#addCC)Adds address to publicly send a copy of message to[setContentType](#setContentType)Sets message body content type (**strongly recommended**)[setDate](#setDate)Sets time message was sent at as date header[setMessageID](#setMessageID)Sets domain name in order to generate a message ID (**strongly recommended**)[setSignature](#setSignature)Sets a DKIM-Signature header is to be generated (**strongly recommended**)[addCustomHeader](#addCustomHeader)Sets a custom header to send in email message[send](#send)Sends message to destinationSimple example:

```
$message = new \Lucinda\Mail\Message("test subject", "Hello, world!");
$message->setMessageID("example.com"); // recommended to prevent message being labeled as spam
$message->setDate(time()); // signals that message was written now
$message->setContentType("text/html", "UTF-8"); // recommended, unless message is ASCII plaintext
$message->addTo(new Address("receiver@asd.com")); // mandatory
$message->setReplyTo(new Address("sender@example.com", "John Doe")); // recommended if message can be replied to
$message->send();
```

\_\_construct[](__construct)
----------------------------

[](#__construct)

This method constructs a mail message by following arguments:

NameTypeDescription$subjectstringSubject of email message (**mandatory**). Must be single-lined!$bodystringBody of email message (**mandatory**). Can be multi-lined!addAttachment[](addAttachment)
------------------------------

[](#addattachment)

Adds an attachment to message body based on argument:

NameTypeDescription$pathstringAbsolute disk path of file to be attached.Example:

```
$message->addAttachment("/foo/bar/baz.jpg");
```

setFrom[](setFrom)
------------------

[](#setfrom)

Sets address of message author as seen by recipients (see: [from](https://tools.ietf.org/html/rfc4021#section-2.1.2) header) based on argument:

NameTypeDescription$addressAddressAddress that appears as message authorUsually calling this method is not necessary, unless developer wants a different *from* address from that default.

Example:

```
$message->setFrom(new \Lucinda\Mail\Address("sender@example.com", "Example.com Team"));
```

setSender[](setSender)
----------------------

[](#setsender)

Sets address of message author as seen by destination mail server (see: [from](https://tools.ietf.org/html/rfc4021#section-2.1.3) header) based on argument:

NameTypeDescription$addressAddressAddress that appears as message authorShould be same as *from* address, unless mail server is sending messages on behalf of someone else.

Example:

```
$message->setSender(new \Lucinda\Mail\Address("sender@example.com", "Example.com Team"));
```

setReplyTo[](setReplyTo)
------------------------

[](#setreplyto)

Sets address to send message replies to (see: [Reply-To](https://tools.ietf.org/html/rfc4021#section-2.1.4) header) based on argument:

NameTypeDescription$addressAddressAddress to send reply toShould always be set IF we desire messages to be replied to.

Example:

```
$message->setReplyTo(new \Lucinda\Mail\Address("sender@example.com", "Example.com Team"));
```

addTo[](addTo)
--------------

[](#addto)

Adds an address to send message to (see: [To](https://tools.ietf.org/html/rfc4021#section-2.1.5) header) based on argument:

NameTypeDescription$addressAddressAddress to send message toAt least one address must always be set!

Example:

```
$message->addTo(new \Lucinda\Mail\Address("destination@server.com"));
```

addCC[](addCC)
--------------

[](#addcc)

Adds an address to send a copy of message to allowing others to notice (see: [Cc](https://tools.ietf.org/html/rfc4021#section-2.1.6) header) based on argument:

NameTypeDescription$addressAddressAddress to send copy of message toExample:

```
$message->addCC(new \Lucinda\Mail\Address("destination@server.com"));
```

addBCC[](addBCC)
----------------

[](#addbcc)

Adds an address to send a copy of message to without others to notice (see: [Bcc](https://tools.ietf.org/html/rfc4021#section-2.1.7) header):

NameTypeDescription$addressAddressAddress to send copy of message toExample:

```
$message->addBCC(new \Lucinda\Mail\Address("destination@server.com"));
```

setContentType[](setContentType)
--------------------------------

[](#setcontenttype)

Sets message body's content type and character set by following arguments (see: [Content-Type](https://tools.ietf.org/html/rfc4021#section-2.2.5) header):

NameTypeDescription$contentTypestringMessage body content type$charsetstringCharacter set of message bodyExample:

```
$message->setContentType("text/html", "UTF-8");
```

setDate[](setDate)
------------------

[](#setdate)

Sets custom date message was sent at based on argument (see: [Date](https://tools.ietf.org/html/rfc4021#section-2.1.1) header):

NameTypeDescription$dateintUNIX time at which message was writtenUsually it is not necessary to send this header unless you want to trick receiver(s) it originated at a different date.

Example:

```
$message->setDate(time()-1000);
```

setMessageID[](setMessageID)
----------------------------

[](#setmessageid)

Sets unique ID of message to send based on argument (see: [Message-ID](https://tools.ietf.org/html/rfc4021#section-2.1.8) header):

NameTypeDescription$domainNamestringYour server's domain name.It is **strongly recommended** to send this header in order to prevent having your message labeled as spam by recipient mail servers!

Example:

```
$message->setMessageID("example.com");
```

setSignature[](setSignature)
----------------------------

[](#setsignature)

Sets a digital signature of message to send based on arguments (see: [DKIM-Signature](https://tools.ietf.org/html/rfc6376) header):

NameTypeDescription$rsaPrivateKeystringRSA private key to sign messages with$rsaPassphrasestringPassword RSA private key was created with, if any (use "" if none)$domainNamestringYour server's domain name (same as that used by *Message-ID*).$dnsSelectorstringName of specific DKIM public key record in your DNS$signedHeadersarrayList of headers that participate in signatureIn order to prevent having your message labeled as spam by recipient mail servers, setting this header is **strongly recommended**! To get values for params above, follow this guide:

- Go to
    - fill *hostname*, which will be value of **$domainName** above (eg: "example.com")
    - write a **$dnsSelector** "subdomain" (eg: "dkim")
    - hit on GENERATE button
- Create a DNS TXT record for **$selector**.\_domainkey.**$domainName**. where value is string shown under "Step 2: Create your public DNS record"
- Store private key shown under "Step 3: Save the private key to your SMTP server" section somewhere. This will become value of **$rsaPrivateKey**
- Since you generated a key without a password **$rsaPassphrase** will always be an empty ""
- Now finally you must choose list of header names to generate signature from (eg: \["From", "Message-ID", "Content-Type"\]) using **$signedHeaders**. See: [recommendations](http://dkim.org/specs/rfc4871-dkimbase.html#choosing-header-fields) for what should be chosen!

The algorithm used in generating DKIM-Signature header has been taken from [php-mail-signature](https://github.com/louisameline/php-mail-signature) and refactored completely because original was chaotic and poorly programmed. The end result was class [DKIM](https://github.com/aherne/php-mailing-api/blob/master/src/DKIM.php)!

Example:

```
$message->setSignature("-----BEGIN RSA PRIVATE KEY----- ... -----END RSA PRIVATE KEY-----", "", "example.com", "dkim", [
    "From",
    "Reply-To",
    "Subject",
    "To"
]);
```

addCustomHeader[](addCustomHeader)
----------------------------------

[](#addcustomheader)

Adds a [RFC-4021](https://tools.ietf.org/html/rfc4021) header not covered by commands above using following arguments:

NameTypeDescription$namestringName of header$valuestringValue of headerExample:

```
$message->addCustomHeader("List-Unsubscribe", "");
```

Above command adds a [List-Unsubscribe](https://tools.ietf.org/html/rfc4021#section-2.1.37) header which allows users to unsubscribe from mailing lists by a button click.

send[](send)
------------

[](#send)

Packs message body and headers, compiles latter with DKIM-Signature (if available) and sends mail to destination.

Example:

```
$message->send();
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

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

Recently: every ~41 days

Total

11

Last Release

1431d ago

Major Versions

v1.0.2 → v2.0.02020-07-19

v1.0.3 → v2.0.12020-07-19

v2.0.x-dev → v3.0.02022-01-01

v1.0.x-dev → v3.0.12022-06-13

PHP version history (3 changes)v2.0.0PHP ^7.1

v2.0.x-devPHP ^8.1

v2.0.2PHP ^7.1|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3382770?v=4)[Lucian Gabriel Popescu](/maintainers/aherne)[@aherne](https://github.com/aherne)

---

Top Contributors

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

---

Tags

mailingOOPdkimdkim-signature

### Embed Badge

![Health badge](/badges/lucinda-mailing/health.svg)

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

###  Alternatives

[nextras/mail-panel

MailPanel is extension for Nette Framework which captures sent e-mails in development mode and shows them in debugger bar.

741.2M4](/packages/nextras-mail-panel)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38425.4k](/packages/bocharsky-bw-arrayzy)[contributte/mailing

Sending emails with pleasure and prepared templates.

16961.0k2](/packages/contributte-mailing)[putyourlightson/craft-campaign

Send and manage email campaigns, contacts and mailing lists.

6435.0k1](/packages/putyourlightson-craft-campaign)[phpcurl/curlwrapper

The simplest OOP wrapper for curl, curl\_multi, curl\_share functions. Use CURL as a dependency, not hard-coded!

11110.4k3](/packages/phpcurl-curlwrapper)[academe/laraveldkim

A Laravel plugin to sign all outgoing emails using DKIM from within the application.

1643.8k](/packages/academe-laraveldkim)

PHPackages © 2026

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