メールを受信するサーバにメール受信用ユーザを登録する。
受信するメールアドレスは[ユーザ名]@ホスト名になります。
# adduser [ユーザ名]
# passwd [パスワード]
# passwd [パスワード]
.forwardに転送設定を記述
/home/[ユーザ名]/.forward
register,”| /usr/bin/php /path/to/autoreply.php
.転送先はphpスクリプト。パイプでメール内容を渡している。
autoreply.php(返信処理の内容)はこんなふうになる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | require_once ( "Mail/mimeDecode.php" ); //REARモジュール //メールソースを標準入力から読み込み $source = file_get_contents ( "php://stdin" ); if (! $source ) { return false; // 読み込み失敗 } //メール解析 $params [ 'include_bodies' ] = true; $params [ 'decode_bodies' ] = true; $params [ 'decode_headers' ] = true; $decoder = new Mail_mimeDecode( $source ); $structure = $decoder ->decode( $params ); // 送信者のメールアドレスを取得する $from_address = mb_convert_encoding(mb_decode_mimeheader( $structure ->headers[ 'from' ]) ,mb_internal_encoding(), "auto" ); |
このスクリプトを標準入力無しで起動すると
$source = file_get_contents(“php://stdin”);
のところで入力待ちになって処理が中断しますが、ヘッダさえもnullなメールを送ることは出来ないので多分気にしなくてもいいはず。