Skip to content

Instantly share code, notes, and snippets.

@Caffe1neAdd1ct
Created February 6, 2014 11:37
Show Gist options
  • Save Caffe1neAdd1ct/8842544 to your computer and use it in GitHub Desktop.
Save Caffe1neAdd1ct/8842544 to your computer and use it in GitHub Desktop.
Stop live emails going out via sendmail
#!/bin/bash
formail -R cc X-original-cc \
-R to X-original-to \
-R bcc X-original-bcc \
-f -A"To: new@email.com" \
| /usr/sbin/sendmail -t -i
# pipe all to a log instead, comment out formail code
#tee -a /tmp/trapmail.log > /dev/null
@Caffe1neAdd1ct
Copy link
Author

Apache config setting:

php_admin_value sendmail_path "/usr/local/bin/sendmail/trapmail > /dev/null"

or for php-fpm:

php_admin_value[sendmail_path] = /usr/local/bin/sendmail/trapmail > /dev/null

@Caffe1neAdd1ct
Copy link
Author

PHPMailer now does a "sanity check" on the sendmail_path to make sure it contains the string "sendmail"

put this script in /usr/local/bin/sendmail/trapmail instead to work round this issue.

Also PHPMailer library has hard coded the sendmail path on $mailer->Sendmail property instead of using ini_get("sendmail") so you now have to do the following to use trapmail with latest PHPMailer:

$mailer = new \PHPMailer(true);
$mailer->Sendmail = ini_get("sendmail_path");
$mailer->IsSendmail();

@Caffe1neAdd1ct
Copy link
Author

formail command is provided by the procmail package on CentOS 6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment