PHPackages                             onlime/sendmail-wrapper - 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. [Database &amp; ORM](/categories/database)
4. /
5. onlime/sendmail-wrapper

ActiveLibrary[Database &amp; ORM](/categories/database)

onlime/sendmail-wrapper
=======================

A powerful sendmail wrapper to log and throttle emails sent by PHP

1.1.0(3y ago)26714GPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Oct 14Pushed 3y ago4 watchersCompare

[ Source](https://github.com/onlime/sendmail-wrapper)[ Packagist](https://packagist.org/packages/onlime/sendmail-wrapper)[ Docs](https://github.com/onlime/sendmail-wrapper)[ RSS](/packages/onlime-sendmail-wrapper/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

sendmail-wrapper
================

[](#sendmail-wrapper)

A powerful sendmail wrapper to log and throttle emails sent by PHP

Advantages
----------

[](#advantages)

- Lets you monitor any mail traffic from PHP scripts
- Allows throttling (limiting) emails sent by PHP's `mail()` function
- Throttle by sent email and/or recipient count per day
- Logs both to syslog and database with message metadata
- Logs common mail headers like `From`, `To`, `Cc`, `Bcc`, `Subject`
- Fixes `Return-Path` header on the fly for users who did not correctly set it
- Highly secured setup, customers cannot access the logging/throttling database
- Standalone PHP application without any external library dependencies
- Built for shared webhosting environments where PHP runs in PHP-FPM (FastCGI Process Manager) mode
- No cronjobs required, sendmail-wrapper will reset counters automatically every day

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

[](#requirements)

- PHP 7.4+
- sendmail compatible MTA: Exim, Postfix,...
- sudo 1.8+

> Currently, sendmail-wrapper is tested and actively used by [Onlime GmbH](https://www.onlime.ch/) on shared webhosting environments with PHP 8.0, 8.1, and 8.2.

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

[](#installation)

### Initial Setup

[](#initial-setup)

Clone repository from GitHub:

```
$ git clone https://github.com/onlime/sendmail-wrapper.git /opt/sendmail-wrapper
```

Setup system user for sendmail-wrapper:

```
$ adduser --system --home /no/home --no-create-home --uid 6000 --group --disabled-password --disabled-login sendmailwrapper
$ adduser sendmailwrapper customers
```

### Quick Install

[](#quick-install)

The installer script **install.sh** will correctly set up permissions and symlink the wrapper scripts:

```
$ cd /opt/sendmail-wrapper/
$ ./install.sh
```

If you wish to run this manually, check the following instructions...

### Manual Install

[](#manual-install)

Set correct permissions:

```
$ chown sendmailwrapper:sendmailwrapper *.php *.ini
$ chmod 400 config.private.ini
$ chmod 444 config.ini config.local.ini
$ chmod 555 sendmail-wrapper.php prepend.php
$ chmod 500 sendmail-throttle.php
$ chmod 400 schema/*.sql
```

Create symlinks:

```
$ ln -sf /opt/sendmail-wrapper/sendmail-wrapper.php /usr/sbin/sendmail-wrapper
$ ln -sf /opt/sendmail-wrapper/sendmail-throttle.php /usr/sbin/sendmail-throttle
$ /bin/cp -a prepend.php /var/www/shared/
```

### Setup sudo

[](#setup-sudo)

Add the following lines to your /etc/sudoers:

```
www-data        ALL = (sendmailwrapper) NOPASSWD:/usr/sbin/sendmail-throttle [0-9]*
%customers      ALL = (sendmailwrapper) NOPASSWD:/usr/sbin/sendmail-throttle [0-9]*

```

### Setup PHP

[](#setup-php)

Add/modify the following in your php.ini:

```
sendmail_path = /usr/sbin/sendmail-wrapper -t -i
auto_prepend_file = /var/www/shared/prepend.php
```

> **NOTE:**It is recommended to put the default `-t -i` options in the `sendmail_path` directive of your php.ini instead of appending them directly to the `sendmailCmd` config option in your `config.local.ini`.
>
> This way, it won't break any projects that use [Symfony Mailer](https://github.com/symfony/mailer/) component which actually checks for `-bs` or `-t` in `sendmail_path`. (see [SendmailTransport.php](https://github.com/symfony/mailer/blob/6.2/Transport/SendmailTransport.php#L57-L59))

### Setup MySQL

[](#setup-mysql)

Import the sendmailwrapper database schema:

```
$ mysql -u root -p
