PHPackages                             nette/mail - 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. nette/mail

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

nette/mail
==========

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

v4.1.0(1mo ago)5389.8M↓24.5%73[3 issues](https://github.com/nette/mail/issues)[2 PRs](https://github.com/nette/mail/pulls)20BSD-3-ClausePHPPHP 8.2 - 8.5CI passing

Since May 11Pushed 2mo ago35 watchersCompare

[ Source](https://github.com/nette/mail)[ Packagist](https://packagist.org/packages/nette/mail)[ Docs](https://nette.org)[ RSS](/packages/nette-mail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (46)Used By (20)

[![Nette Mail](https://private-user-images.githubusercontent.com/194960/331234219-8b2371bd-0976-443c-b60a-460eb8b3222f.jpg?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQzNDE2NDksIm5iZiI6MTc3NDM0MTM0OSwicGF0aCI6Ii8xOTQ5NjAvMzMxMjM0MjE5LThiMjM3MWJkLTA5NzYtNDQzYy1iNjBhLTQ2MGViOGIzMjIyZi5qcGc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMzI0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDMyNFQwODM1NDlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hMWU3OWNiNzE2MzY4MjA5ZWIyYWZiMzExNjBjNjEwN2YwOWJjZDhkNDEzY2EwZmE4OTFiMzZlNjY3MTgxMTg4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.Kw7z0Riy-QoQyD5JGnWsYVE6lG5TyuaR6bogvhciaXo)](https://doc.nette.org/en/mail)

[![Downloads this Month](https://camo.githubusercontent.com/347d788daa691a3bb47ab06aeb1bfc561610af91ef72340450e6612205fcada3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6e657474652f6d61696c2e737667)](https://packagist.org/packages/nette/mail)[![Tests](https://github.com/nette/mail/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/mail/actions)[![Coverage Status](https://camo.githubusercontent.com/3a7507aab61aa2916d2eeda02df9939c841d37da036c64acc5fe51c33eab8180/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6e657474652f6d61696c2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/nette/mail?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/a3c47c5312d5d1835b0c312ef71cd99b62371b4043c12c020d75c26299be365d/68747470733a2f2f706f7365722e707567782e6f72672f6e657474652f6d61696c2f762f737461626c65)](https://github.com/nette/mail/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/nette/mail/blob/master/license.md)

Introduction
------------

[](#introduction)

Are you going to send emails such as newsletters or order confirmations? Nette Framework provides the necessary tools with a very nice API.

Documentation can be found on the [website](https://doc.nette.org/en/mail).

[Support Me](https://github.com/sponsors/dg)
--------------------------------------------

[](#support-me)

Do you like Nette Mail? Are you looking forward to the new features?

[![Buy me a coffee](https://camo.githubusercontent.com/afa7c20ccaac10ac4f1f51669bafb212856b932e0c8b276cb290336cf08624b8/68747470733a2f2f66696c65732e6e657474652e6f72672f69636f6e732f646f6e6174696f6e2d332e737667)](https://github.com/sponsors/dg)

Thank you!

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

[](#installation)

```
composer require nette/mail
```

It requires PHP version 8.2 and supports PHP up to 8.5.

Creating Emails
===============

[](#creating-emails)

Email is a [Nette\\Mail\\Message](https://api.nette.org/3.0/Nette/Mail/Message.html) object:

```
$mail = new Nette\Mail\Message;
$mail->setFrom('John ')
	->addTo('peter@example.com')
	->addTo('jack@example.com')
	->setSubject('Order Confirmation')
	->setBody("Hello, Your order has been accepted.");
```

All parameters must be encoded in UTF-8.

In addition to specifying recipients with the `addTo()` method, you can also specify the recipient of copy with `addCc()`, or the recipient of blind copy with `addBcc()`. All these methods, including `setFrom()`, accepts addressee in three ways:

```
$mail->setFrom('john.doe@example.com');
$mail->setFrom('john.doe@example.com', 'John Doe');
$mail->setFrom('John Doe ');
```

The body of an email written in HTML is passed using the `setHtmlBody()` method:

```
$mail->setHtmlBody('Hello,Your order has been accepted.');
```

You don't have to create a text alternative, Nette will generate it automatically for you. And if the email does not have a subject set, it will be taken from the `` element.

Images can also be extremely easily inserted into the HTML body of an email. Just pass the path where the images are physically located as the second parameter, and Nette will automatically include them in the email:

```
// automatically adds /path/to/images/background.gif to the email
$mail->setHtmlBody(
	'Hello ',
	'/path/to/images',
);
```

The image embedding algorithm supports the following patterns: ``, ``, `url(...)` inside the HTML attribute `style` and special syntax `[[...]]`.

Can sending emails be even easier?

Emails are like postcards. Never send passwords or other credentials via email.

Attachments
-----------

[](#attachments)

You can, of course, attach attachments to email. Use the `addAttachment(string $file, string $content = null, string $contentType = null)`.

```
// inserts the file /path/to/example.zip into the email under the name example.zip
$mail->addAttachment('/path/to/example.zip');

// inserts the file /path/to/example.zip into the email under the name info.zip
$mail->addAttachment('info.zip', file_get_contents('/path/to/example.zip'));

// attaches new example.txt file contents "Hello John!"
$mail->addAttachment('example.txt', 'Hello John!');
```

Templates
---------

[](#templates)

If you send HTML emails, it's a great idea to write them in the [Latte](https://latte.nette.org) template system. How to do it?

```
$latte = new Latte\Engine;
$params = [
	'orderId' => 123,
];

$mail = new Nette\Mail\Message;
$mail->setFrom('John ')
	->addTo('jack@example.com')
	->setHtmlBody(
		$latte->renderToString('/path/to/email.latte', $params),
		'/path/to/images',
	);
```

File `email.latte`:

```

	Order Confirmation

	body {
		background: url("background.png")
	}

	Hello,

	Your order number {$orderId} has been accepted.

```

Nette automatically inserts all images, sets the subject according to the `` element, and generates text alternative for HTML body.

Sending Emails
==============

[](#sending-emails)

Mailer is class responsible for sending emails. It implements the [Nette\\Mail\\Mailer](https://api.nette.org/3.0/Nette/Mail/Mailer.html) interface and several ready-made mailers are available which we will introduce.

SendmailMailer
--------------

[](#sendmailmailer)

The default mailer is SendmailMailer which uses PHP function `mail()`. Example of use:

```
$mailer = new Nette\Mail\SendmailMailer;
$mailer->send($mail);
```

If you want to set `returnPath` and the server still overwrites it, use `$mailer->commandArgs = '-fmy@email.com'`.

SmtpMailer
----------

[](#smtpmailer)

To send mail via the SMTP server, use `SmtpMailer`.

```
$mailer = new Nette\Mail\SmtpMailer(
	host: 'smtp.gmail.com',
	username: 'franta@gmail.com',
	password: '*****',
	encryption: Nette\Mail\SmtpMailer::EncryptionSSL,
);
$mailer->send($mail);
```

The following additional parameters can be passed to the constructor:

- `port` - if not set, the default 25 or 465 for `ssl` will be used
- `timeout` - timeout for SMTP connection
- `persistent` - use persistent connection
- `clientHost` - client designation
- `streamOptions` - allows you to set [SSL context options](https://www.php.net/manual/en/context.ssl.php) for connection

FallbackMailer
--------------

[](#fallbackmailer)

It does not send email but sends them through a set of mailers. If one mailer fails, it repeats the attempt at the next one. If the last one fails, it starts again from the first one.

```
$mailer = new Nette\Mail\FallbackMailer([
	$smtpMailer,
	$backupSmtpMailer,
	$sendmailMailer,
]);
$mailer->send($mail);
```

Other parameters in the constructor include the number of repeat and waiting time in milliseconds.

DKIM
====

[](#dkim)

DKIM (DomainKeys Identified Mail) is a trustworthy email technology that also helps detect spoofed messages. The sent message is signed with the private key of the sender's domain and this signature is stored in the email header. The recipient's server compares this signature with the public key stored in the domain's DNS records. By matching the signature, it is shown that the email actually originated from the sender's domain and that the message was not modified during the transmission of the message.

```
$signer = new Nette\Mail\DkimSigner(
	domain: 'nette.org',
	selector: 'dkim',
	privateKey: file_get_contents('../dkim/dkim.key'),
	passPhrase: '****',
);

$mailer = new Nette\Mail\SendmailMailer; // or SmtpMailer
$mailer->setSigner($signer);
$mailer->send($mail);
```

###  Health Score

78

—

ExcellentBetter than 100% of packages

Maintenance87

Actively maintained with recent releases

Popularity67

Solid adoption and visibility

Community52

Growing community involvement

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86.8% 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 ~98 days

Recently: every ~218 days

Total

45

Last Release

53d ago

Major Versions

v2.4.6 → v3.0.02019-04-01

v2.4.x-dev → v3.1.62021-02-24

v3.1.10 → v4.0.02023-01-26

v3.1.x-dev → v4.0.32024-10-05

PHP version history (13 changes)v2.2.0PHP &gt;=5.3.1

v2.4.0PHP &gt;=5.6.0

v3.0.0PHP &gt;=7.1

v2.4.x-devPHP &gt;=5.6 &lt;8.1

v3.1.6PHP &gt;=7.1 &lt;8.1

v3.1.8PHP &gt;=7.1 &lt;8.2

v3.1.9PHP &gt;=7.1 &lt;8.3

v4.0.0PHP &gt;=8.0 &lt;8.3

v4.0.1PHP 8.0 - 8.3

v3.1.11PHP 7.1 - 8.3

v4.0.3PHP 8.0 - 8.4

v4.0.4PHP 8.0 - 8.5

v4.1.0PHP 8.2 - 8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f266513a3ca97500ec3d85d562b9279c7a6346358fe2b8d90390ece717a027?d=identicon)[david@grudl.com](/maintainers/david@grudl.com)

---

Top Contributors

[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (323 commits)")[![kravco](https://avatars.githubusercontent.com/u/115938?v=4)](https://github.com/kravco "kravco (7 commits)")[![janbarasek](https://avatars.githubusercontent.com/u/4738758?v=4)](https://github.com/janbarasek "janbarasek (5 commits)")[![JanTvrdik](https://avatars.githubusercontent.com/u/175109?v=4)](https://github.com/JanTvrdik "JanTvrdik (4 commits)")[![vrana](https://avatars.githubusercontent.com/u/117453?v=4)](https://github.com/vrana "vrana (4 commits)")[![dundee](https://avatars.githubusercontent.com/u/27106?v=4)](https://github.com/dundee "dundee (2 commits)")[![jakubboucek](https://avatars.githubusercontent.com/u/1657322?v=4)](https://github.com/jakubboucek "jakubboucek (2 commits)")[![xificurk](https://avatars.githubusercontent.com/u/117465?v=4)](https://github.com/xificurk "xificurk (2 commits)")[![enumag](https://avatars.githubusercontent.com/u/539462?v=4)](https://github.com/enumag "enumag (2 commits)")[![lukaspijak](https://avatars.githubusercontent.com/u/2571714?v=4)](https://github.com/lukaspijak "lukaspijak (1 commits)")[![mstrouhal](https://avatars.githubusercontent.com/u/7405673?v=4)](https://github.com/mstrouhal "mstrouhal (1 commits)")[![mzk](https://avatars.githubusercontent.com/u/382475?v=4)](https://github.com/mzk "mzk (1 commits)")[![ondrejcech](https://avatars.githubusercontent.com/u/4385840?v=4)](https://github.com/ondrejcech "ondrejcech (1 commits)")[![pavolbiely](https://avatars.githubusercontent.com/u/115791?v=4)](https://github.com/pavolbiely "pavolbiely (1 commits)")[![pepakriz](https://avatars.githubusercontent.com/u/383294?v=4)](https://github.com/pepakriz "pepakriz (1 commits)")[![petrkle](https://avatars.githubusercontent.com/u/545514?v=4)](https://github.com/petrkle "petrkle (1 commits)")[![podolinek](https://avatars.githubusercontent.com/u/1062993?v=4)](https://github.com/podolinek "podolinek (1 commits)")[![pracj3am](https://avatars.githubusercontent.com/u/191928?v=4)](https://github.com/pracj3am "pracj3am (1 commits)")[![robbertkl](https://avatars.githubusercontent.com/u/5704510?v=4)](https://github.com/robbertkl "robbertkl (1 commits)")[![storkdork](https://avatars.githubusercontent.com/u/399349?v=4)](https://github.com/storkdork "storkdork (1 commits)")

---

Tags

htmlmailmailernettenette-frameworkphpnettemailmimemailersmtp

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nette-mail/health.svg)

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

###  Alternatives

[zbateson/mail-mime-parser

MIME email message parser

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

A fully tested email parser for PHP 8.0+ (mailparse extension wrapper).

9979.6M27](/packages/php-mime-mail-parser-php-mime-mail-parser)[zbateson/stream-decorators

PHP psr7 stream decorators for mime message part streams

4748.6M6](/packages/zbateson-stream-decorators)[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)[contributte/mailing

Sending emails with pleasure and prepared templates.

16961.0k2](/packages/contributte-mailing)

PHPackages © 2026

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