バウンスしたメールを php スクリプトに転送して処理したいと考えています。私は使っている。
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
?>
完璧に動作します!しかし、バウンスされたメッセージの「To」フィールドを収集するにはどうすればよいでしょうか? $to 変数を追加しようとしましたが、うまくいきません。
どんな助けでも素晴らしいでしょう、
ありがとう、
編集:実際には、メッセージの本文内に「TO」フィールドを取得する必要があります。- 返送元のメール。メッセージの本文を分解して特定の情報を取得するにはどうすればよいですか? この情報を簡単に取得できるように、その人の電子メールで特別なヘッダーを作成する必要がありますか?