June 10, 2008

Postfix - pass a mail to the php script

ある特定のユーザ、もしくはドメイン宛のメールをPHPに渡す場合のPostfixの設定。

まず、transportの設定をする。全ユーザの場合はドメイン名だけで良い。
$ vi /etc/postfix/transport

user@example.com phpscript:
# example.com phpscript:
main.cfでこのファイルを指定する。
$ vi /etc/postfix/transport

transport_maps = hash:/etc/postfix/transport
postmapコマンドでtransport.dbを更新する。
$ /usr/sbin/postmap /etc/postfix/transport
master.cfで"phpscript"サービスの設定をする。
$ vi /etc/postfix/master.cf

phpscript unix  -      n      n      -      -      pipe
  flags= user=nobody argv=/path/to/php /path/to/script.php
postfixを再起動する。
$ /etc/init.d/postfix restart
phpではstdinからメールのソースを取得できる。
$ vi /path/to/script.php

<?php

$mail = file_get_contents("php://stdin");


トラックバックURL

コメントする

名前:
URL:
  情報を記憶: 評価:  顔   星
 
 
 
Sabel

Sabel PHP Frameworkを開発しています。
http://www.sabel.jp/

Search
Categories
Tags
Recent Articles
Archives