Created
July 6, 2017 01:40
-
-
Save ahgood/f0a7c03dd1dbb397ee25ea710d05bf75 to your computer and use it in GitHub Desktop.
Postfix and Procmail to monitor incoming email and trigger PHP script sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install Postfix and Procmail: | |
yum install postfix | |
yum install procmail | |
(Optional)Setup mail relay: /etc/postfix/main.cf | |
relayhost = [Relay server IP] | |
Setup procmail: /etc/postfix/main.cf | |
mailbox_command = /usr/bin/procmail | |
Configuration: $HOME/.procmailrc | |
PATH=/usr/local/bin:/bin:/usr/bin | |
LOGFILE=$HOME/procmail.log | |
VERBOSE=YES | |
SHELL=/bin/sh | |
:0 | |
* ^Subject:.*BANK* | |
| $HOME/sendmail.php | |
PHP script: $HOME/sendmail.php | |
#!/usr/bin/php | |
<?php | |
$to = '[email protected]'; | |
$subject = 'Test email bank'; | |
$message = ''; | |
$headers = 'From: [email protected]' . "\r\n" . | |
'Reply-To: [email protected]' . "\r\n" . | |
'X-Mailer: PHP/' . phpversion(); | |
$stdin = fopen('php://stdin', 'r'); | |
$line = fgets($stdin); | |
$message .= $line; | |
mail($to, $subject, $message, $headers); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment