コードを舐める日々

わからないことがわからないことをしる日々

メール解析@PHPその5

実際にメール内容をプログラムに渡して処理するテスト。

さくられんさばにも設定済み。

PHPPEARライブラリのmimeDecodeクラスを使うんだな。
atseason.com: The Leading AT Season Site on the Net

参考プログラムはここ↓

携帯の空メール機能を実装 « kawama.jp

<?php

//PEARのライブラリ読み込み
require_once("Mail/mimeDecode.php");

//メールソースを標準入力から読み込み
$source = file_get_contents("php://stdin");
if(!$source) {
    exit();    // 読み込み失敗
}

//メール解析
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($source);
$structure = $decoder->decode($params);
$from = mb_convert_encoding(mb_decode_mimeheader($structure->headers['from']), mb_internal_encoding(), "auto");

//メール返信
$to = $from;
$title = "返信";
$body = "登録完了";
$from = "From: a@hogehoge.com";

mb_internal_encoding("SJIS");
mb_language("japanese");
mb_send_mail($to, $title, $body, $from);
?>
   ----- The following addresses had permanent fatal errors -----
<a@hogehoge.com>
    (reason: 2)

   ----- Transcript of session follows -----
/home/hogehoge/www/mail/mail.php: cannot open ?php: No such file or directory
554 5.3.0 unknown mailer error 2

おや、なぜだろう。
ググってみると、SAKURAでメールを受信する毎にプログラムを起動したいのですが上.. - 人力検索はてな

.mailfilterのパーミッションを600にするべし。
telnet使えないところにいるので帰宅してやってみよう。