0

サーバーに電子メール傍受を設定しました。

以下は、サーバーに設定された私のメールフォワーダーです

testemail@my.server.com,"/home/server/php_pipe_mail.php"

以下はphp_pipe_mail.phpの私のコードです

#!/usr/bin/php -q
<?php 

require_once('mimeDecode.php');
include('sql-connect.php');
error_reporting(E_ALL);


ob_start();


$raw_email = '';



if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin \n";
}

// ABLE TO READ THE MAIL
else
{
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}



$raw_email = preg_replace('/ +/', ' ', $raw_email);


var_dump($raw_email);


$buf = ob_get_contents();

$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $buf;
$params['crlf'] = "\r\n"; 

//Creating temp file on server 
$myFile = "amail.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $buf);
fclose($fh);


//Generating mail structure in object format
$structure = Mail_mimeDecode::decode($params); 
$attachment = array();

$mail_date= date( 'Y-m-d H:i:s', strtotime($structure->headers['date']) );
$from = $structure->headers['from'];
$to = $structure->headers['to'];
$subject = htmlentities($structure->headers['subject'],ENT_QUOTES);
if($structure->ctype_primary == "multipart")
{
    $body_text = $structure->parts[0]->parts[0]->body;
$body_html = $structure->parts[0]->parts[1]->body;

$x = 0;
//fetch attachment
foreach ($structure->parts as $part) {
    // only save if an attachment
    if (isset($part->disposition) and ($part->disposition=='attachment')) {
        $attachment[$x]["filename"] = $part->d_parameters['filename'];
        $attachment[$x]["content_type"] = $part->ctype_primary . "/" .          $part->ctype_secondary;
        $attachment[$x]["body"] = addslashes($part->body);
        $x++;
    }
}
}
else 
{
$body_text = $structure->parts[0]->body;
$body_html = $structure->parts[1]->body;
}


$qry1 = "insert into mail_buffer(mail_date,mail_from,     mail_to,mail_subject,mail_text_body,mail_html_body) Values('". $mail_date ."','".$from."','".$to."','".$subject."','".$body_text."','".$body_html."')";

mysql_query($qry1) or die(mysql_error($con));

$last_id = mysql_insert_id();

if(count($attachment) > 0)
{
for($i=0; $i < count($attachment); $i++)
{
    $qry = "insert into mail_attachment(email_id,content_type, file_name,body) Values('". $last_id ."','".$attachment[$i]['content_type']."','".$attachment[$i]['filename']."','".$attachment[$i]['body']."')";
    mysql_query($qry) or die(mysql_error($con));
}
}



mysql_close($con);

ob_end_clean();

?>

上記のスクリプトは完全に正常に動作します。

メッセージのヘッダー、本文、添付ファイルを取得でき、問題なくデータベースに保存できます。

添付ファイルのない電子メールが届くと、すべて正常に機能し、電子メールは私が傍受している電子メール アドレスに配信されます。

しかし、以下は機能していません。

メール コンテンツがデータベースに保存されているよりも添付ファイル付きのメールが届いたが、メールがメール アドレスに配信されない場合、傍受していて、バウンス バック メールに次のエラー メッセージが表示されます。

送信したメッセージは、1 人以上の受信者に配信できませんでした。これは永続的なエラーです。次のアドレスは失敗しました:

testemail@my.server.com によって生成された |/home/server/php_pipe_mail.php へのパイプ

この件に関して誰か助けてくれませんか。

ありがとう。

4

1 に答える 1

0

添付ファイルが存在する場合、スクリプトが何かをエコーし​​ている可能性はありますか? 以前に電子メールのパイピングに問題があり、失敗メッセージが送信者に返されるのを見たことがあります。これは、パイピング スクリプトが何らかの出力を生成したことが原因でした。おそらくerror_reporting(E_ALL);、スクリプトが出力を生成することを許可している可能性があります-試してくださいerror_reporting(0);

于 2011-05-28T10:58:28.530 に答える