空メール処理
なんか空メール処理が流行りらしいので。
空メール送信
mail@example.jp
空メール返信
info@example.jp
空メール処理スクリプト。
PEAR::Mail_mineDecode使えるなら使うべきです。
PEARを無駄に嫌う人がいますが世界中の人にデバッグしているわけですので、俺俺処理よりもよっぽど信頼できます。
<?php
mb_language('ja');
mb_internal_encoding('SjIS-win');
if (!$input = file_get_contents('php://stdin')) {
print 'input error';
exit;
}
if (!preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $input_matches)) {
print 'mail parse error';
exit;
}
if (!preg_match("/(?:^|\r?\n)from:\s(.+)(?:\r?\n|$)/is", $input_matches[1], $header_matches)) {
print 'header parse error';
exit;
}
$to = $header_matches[1];
if (preg_match('/<(.+)>/', $to, $to_matches)) {
$to = $to_matches[1];
}
$subject = 'タイトル';
$body = '本文';
$from = 'info@example.jp';
$headers = "From: {$from}\r\n"
. "Reply-To: {$from}\r\n"
. "Return-Path: {$from}";
if ($to == $from) {
exit;
}
$subject = mb_encode_mimeheader($subject);
mb_send_mail($to, $subject, $body, $headers);
MTA毎の空メール設定。
予備としてadmin@example.jpへ転送しておきます。
○qmail
/var/qmail/alias
/path/to/.qmail-mail(VirtualHost利用時)
"|/usr/bin/php /path/to/cli/tempmail.php >> /var/log/tempmail/example_jp.log"
&admin@example.jp
○Postfix
/etc/postfix/aliases
mail: admin,"|/usr/bin/php /path/to/cli/tempmail.php >> /var/log/tempmail/example_jp.log"
カテゴリー: 日記