2009-08-02 11 views
4

私は受信メールを受け取り、必要に応じて操作できるphp変数に "送信者"と "メッセージ"を分解するプログラムをセットアップしようとしていますが、どこから起動するのかわかりません。php email piping

私はすでにメールアドレス(cPanelのを経由して)問題のPHPファイルにパイプ持って

答えて

2

スタートで:

$lines = explode("\n",$message_data); 
$headers = array(); 
$body = ''; 

$in_body = false; 

foreach($lines as $line) 
{ 
    if($in_body) 
    { 
      $body .= $line; 
    } 
    elseif($line == '') 
    { 
      $in_body = true; 
    } 
    else 
    { 
      list($header_name,$header_value) = explode(':',$line,2); 
      $headers[$header_name] = $header_body; 
    } 
} 

// now $headers is an array of all headers and you could get the from address via $headers['From'] 
// $body contains just the body 

私はちょうど私の頭の上オフと書きました。構文やエラーをテストしていません。ちょうど出発点。

2

eZコンポーネントezcMailParserクラスをご覧ください。インターフェイスを実装する必要があります(ezcMailParserSet)。ここで

+0

私はこのソリューションが自分のものよりも好きです – Josh

2

は、溶液中に魔法のように

#!/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; 
} 
} 
echo $from; 
echo $subject; 
echo $headers; 
echo $message; 
?> 

作品を働いています。

+0

私はあなたが私の質問をチェックアウトするように頼むようにとても失礼になります:http://stackoverflow.com/questions/12619056/passing-paremeters-from-php-email-piping送信されるすべての細部からメッセージをフィルタリングする助けが必要です。感謝万円。 – Smudger