dev-master
9999999-dev https://github.com/onlime/sendmail-wrapperA powerful sendmail wrapper to log and throttle emails sent by PHP
GPLv3
The Requires
- php >=5.4.0
- ext-mbstring *
- ext-pdo *
by Philip Iezzi
php wrapper mysql throttling sendmail mta
Wallogit.com
2017 © Pedro Peláez
A powerful sendmail wrapper to log and throttle emails sent by PHP
A powerful sendmail wrapper to log and throttle emails sent by PHP, (*1)
mail() functionFrom, To, Cc, Bcc, Subject
Return-Path header on the fly for users who did not correctly set itCurrently, sendmail-wrapper is tested and actively used by Onlime GmbH on shared webhosting environments with PHP 8.0, 8.1, and 8.2., (*2)
Clone repository from GitHub:, (*3)
$ git clone https://github.com/onlime/sendmail-wrapper.git /opt/sendmail-wrapper
Setup system user for sendmail-wrapper:, (*4)
$ adduser --system --home /no/home --no-create-home --uid 6000 --group --disabled-password --disabled-login sendmailwrapper $ adduser sendmailwrapper customers
The installer script install.sh will correctly set up permissions and symlink the wrapper scripts:, (*5)
$ cd /opt/sendmail-wrapper/ $ ./install.sh
If you wish to run this manually, check the following instructions..., (*6)
Set correct permissions:, (*7)
$ 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:, (*8)
$ 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/
Add the following lines to your /etc/sudoers:, (*9)
www-data ALL = (sendmailwrapper) NOPASSWD:/usr/sbin/sendmail-throttle [0-9]* %customers ALL = (sendmailwrapper) NOPASSWD:/usr/sbin/sendmail-throttle [0-9]*
Add/modify the following in your php.ini:, (*10)
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 -ioptions in thesendmail_pathdirective of your php.ini instead of appending them directly to thesendmailCmdconfig option in yourconfig.local.ini., (*11)This way, it won't break any projects that use Symfony Mailer component which actually checks for
-bsor-tinsendmail_path. (see SendmailTransport.php), (*12)
Import the sendmailwrapper database schema:, (*13)
$ mysql -u root -p < schema/schema.mysql.sql
Create a MySQL user with the following permissions:, (*14)
GRANT USAGE ON *.* TO sendmailwrapper@'localhost' IDENTIFIED BY '********'; GRANT SELECT, INSERT, UPDATE ON sendmailwrapper.throttle TO sendmailwrapper@'localhost'; GRANT INSERT ON sendmailwrapper.messages TO sendmailwrapper@'localhost';
Default configuration can be found in config.ini:, (*15)
[global] defaultTZ = Europe/Zurich adminTo = hostmaster@example.com adminFrom = hostmaster@example.com [wrapper] sendmailCmd = "/usr/sbin/sendmail" throttleCmd ="sudo -u sendmailwrapper /usr/sbin/sendmail-throttle" throttleOn = true defaultHost = "example.com" syslogPrefix = sendmail-wrapper-php xHeaderPrefix = "X-Example-" [throttle] countMax = 1000 rcptMax = 1000 syslogPrefix = sendmail-throttle-php adminSubject = "Sendmail limit exceeded" [db] dsn = "mysql:host=localhost;dbname=sendmailwrapper" user = sendmailwrapper pass = "xxxxxxxxxxxxxxxxxxxxx"
You should not change any of the above values. Create your own config.local.ini instead to overwrite some values, e.g.:, (*16)
[global] adminTo = hostmaster@mydomain.com adminFrom = hostmaster@mydomain.com [wrapper] defaultHost = "mydomain.com" xHeaderPrefix = "X-MyCompany-"
Never put your database password in any of the above configuration files. Use another configuration file called config.private.ini instead, e.g.:, (*17)
[db] pass = "mySuper-SecurePassword/826.4287+foo"
To avoid problems with projects that use Symfony Mailer (Laravel's Mail component also uses Symfony Mailer under the hood!), we have moved the default sendmail command-line options -t -i from Sendmail-wrapper's configuration config.ini to the recommended sendmail_path directive in php.ini.
If you stick with our default configuration, you need to update your php.ini:, (*18)
- sendmail_path = /usr/sbin/sendmail-wrapper + sendmail_path = /usr/sbin/sendmail-wrapper -t -i
If you don't care about Symfony Mailer or any other mailer components that check for -t existence in sendmail_path, you can keep the old php.ini configuration and add this to your config.local.ini:, (*19)
sendmailCmd = "/usr/sbin/sendmail -t -i"
A powerful sendmail wrapper to log and throttle emails sent by PHP
GPLv3
php wrapper mysql throttling sendmail mta