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

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

ikkez/f3-mailer
===============

SMTP plugin wrapper for PHP Fat-Free Framework

v1.2.3(4y ago)198.7k↓33.3%2[4 issues](https://github.com/ikkez/f3-mailer/issues)2GPL-3.0PHP

Since Oct 23Pushed 4y ago7 watchersCompare

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

READMEChangelog (9)DependenciesVersions (11)Used By (2)

Sugar Mailer
============

[](#sugar-mailer)

This is a little mail plugin that contains:

- SMTP plugin wrapper
- easily send plain text, html or both text &amp; html hybrid content mails
- convenient methods to add one or multiple recipients
- encode special chars for mails with ISO charset
- ping and jump methods for tracking read and click events in your html mails
- save mails as files to disk

Getting started
---------------

[](#getting-started)

This plugin is configurable via [config file](https://github.com/ikkez/f3-mailer/blob/master/mailer_config.sample.ini):

```
[mailer]
; smtp config
smtp.host = smtp.domain.com
smtp.port = 25
smtp.user = info@domain.com
smtp.pw = 123456789!
; scheme could be SSL or TLS
smtp.scheme =

; optional mail settings
from_mail = noreply@domain.com
from_name = Mario Bros.
; mail to receive bounced mails
errors_to = bounce@domain.com
; used mail for replies to the sent mail
reply_to = info@domain.com

; handler for SMTP errors
on.failure = \Controller\Mail::logError
; handler for tracing opened mails
on.ping = \Controller\Mail::traceMail
; handler for redirecting jump links
on.jump = \Controller\Mail::traceClick
; automatically create jump links in all  tags
jumplinks = true
; path for storing mail dumps
storage_path = logs/mail/
```

Usage
-----

[](#usage)

A little sample looks like this:

```
function send_test($email, $title=null) {
	$mail = new \Mailer();
	$mail->addTo($email, $title);
	$mail->setText('This is a Test.');
	$mail->setHTML('This is a Test.');
	$mail->send('Test Mail Subject');
}
```

If you want, you can change the encoding type that is used for the email body and header when instantiating the mail object with a constructor argument:

```
$mail = new \Mailer('UTF-8'); // default
$mail = new \Mailer('ISO-8859-1');
$mail = new \Mailer('ISO-8859-15');
```

Tracking
--------

[](#tracking)

To initialize the tracking routes, call this before `$f3->run()`:

```
$f3->config('mailer_config.ini');
// ...
Mailer::initTracking();
// ...
$f3->run();
```

To add the ping tracking pixel (1x1 transparent 8bit PNG), put this in your html mail body:

```

```

The file name should be a unique hash you can use to identify the recipient who read your mail.

The tracking methods could look like this:

```
static public function logError($mailer, $log) {
	$logger = new \Log('logs/smtp_'.date('Y_m_d').'.log');
	$logger->write($log);
}

static public function traceMail($hash) {
	// your mail $hash is being read
}

static public function traceClick($target) {
	// someone clicked $target link
}
```

Mock &amp; Storage
------------------

[](#mock--storage)

In case you don't want to actually send the email, but just want to run a test flight and save the mail in a text file, you can mock the server dialog:

```
$mail->send($subject, TRUE); // mock call
$mail->save('newsletter.eml'); // save to file in 'mailer.storage_path' directory
$mail->reset();
```

If you want to keep using the object after a mock call, you need to reset the mailer and add recipients, content and attachments again.

The mail file includes all file attachments.

Logging
-------

[](#logging)

You can log the full SMTP server dialog after sending the email. This could be useful for debugging purposes or as a sending confirmation.

```
$success = $mailer->send($subject);
$f3->write('SMTP_mail.log', $this->mailer->log());
```

**Notice:** By default, the log level is `verbose`, which means it also contains the mail body and attachments, which might eat up a lot of memory. To reduce the log level, set `$log` to `TRUE` (dialog only) or `FALSE` (disabled) in:

```
$mailer->send($subject, $mock, $log);
```

Keep in mind that when you write down mails to files, it can only store what was found in the SMTP log, hence it only works when logging level is `verbose`.

Demo &amp; Testing
------------------

[](#demo--testing)

There's a test bench available here:

API
---

[](#api)

### addBcc

[](#addbcc)

Adds a blind carbon copy recipient.

`addBcc($email, $title=null)`

### addCc

[](#addcc)

Adds a carbon copy recipient.

`addCc($email, $title=null)`

### addTo

[](#addto)

Adds a direct recipient. `addTo($email, $title=null)`

### attachFile

[](#attachfile)

Adds a file attachment.

`attachFile($path, $alias=null, $cid=null)`

### initSMTP

[](#initsmtp)

Initializes SMTP plugin. Useful if you want to reuse the Mailer object but with a fresh SMTP adapter beneath. It's possible to change options before, i.e. to use a different smtp server.

### initTracking

[](#inittracking)

This registers the required routes to F3

### log

[](#log)

Returns SMTP log

### reset

[](#reset)

Reset recipients if key was given, or restart whole smtp plugin.

`($key=null)`

### save

[](#save)

Save the send mail to disk

`save($filename)`

### send

[](#send)

Send message

`send($subject [, $mock = false [, $log = 'verbose']])`

log level options: `FALSE`, `TRUE`, `'verbose'`

### set

[](#set)

Set encoded header value

`set($key, $val)`

### setContent

[](#setcontent)

Set message contents by mime type

`setContent($data [, $mime [, $charset=NULL ]])`

I.e. for AMP mails:

`$mailer->setContent($amp,'text/x-amp-html');`

### setErrors

[](#seterrors)

Set receipient for bounce error mails

`setErrors($email [, $title=null])`

### setFrom

[](#setfrom)

Set message sender

`setFrom($email [, $title=null])`

### setHTML

[](#sethtml)

set message in HTML text format

`setHTML($message)`

### setReply

[](#setreply)

set reply-to field respected by most email clients

`setReply($email [, $title=null])`

### setText

[](#settext)

set message in plain text format

`setText($message)`

License
-------

[](#license)

You are allowed to use this plugin under the terms of the GNU General Public License version 3 or later.

Copyright (C) 2022 Christian Knuth \[ikkez\]

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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 ~215 days

Recently: every ~262 days

Total

10

Last Release

1553d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84cac52f5889d2bf6e710f2139dfc884824b2d7ce9c48a3bfe90704a94c85722?d=identicon)[ikkez](/maintainers/ikkez)

---

Top Contributors

[![ikkez](https://avatars.githubusercontent.com/u/1177647?v=4)](https://github.com/ikkez "ikkez (27 commits)")[![i-k-o](https://avatars.githubusercontent.com/u/4180065?v=4)](https://github.com/i-k-o "i-k-o (2 commits)")[![anystar](https://avatars.githubusercontent.com/u/2850952?v=4)](https://github.com/anystar "anystar (1 commits)")

---

Tags

fat-free-frameworkmailsmtpmailemailsmtpF3fatfree

### Embed Badge

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

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

###  Alternatives

[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)

PHPackages © 2026

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