linux+postfixによる空メール設定手順

まず、postfixをインストール

#yum install postfix

設定変更

#vi /etc/postfix/main.cf

変更項目
myhostname=ホスト名
mydomain=ホスト名
inet_interfaces=all
mydestination = $myhostname,localhost.$mydomain, $mydomain
mynetworks = 192.168.1.0/24, 127.0.0.0/8

メールエイリアス変更

#vi /etc/aliases

「test@ホスト名」送信時に、コマンドを実行するようにする。

test:        "|date >> /tmp/a.txt"

メールエイリアスを反映

#postalias /etc/aliases

sendmailからpostfixに切り替える

# ln -s -f /usr/sbin/sendmail.postfix /etc/alternatives/mta
# /etc/init.d/sendmail stop

postfix起動

#postfix start

メール送信確認

# echo 123 | mail -s mysubject test@ホスト名

実行確認

# cat /tmp/a.txt

※確認できなかったら、/var/log/maillogでエラーを確認。

PHPを起動するように変更
/etc/aliases にて、
testphp: "|/usr/bin/php /tmp/test.php >> /tmp/php_log.txt"
とし、

postaliase /etc/aliases
postfix reload
# echo 123 | mail -s mysubject testphp@ホスト名
# cat /tmp/php_log.txt

とする。