如何避免获取电子邮件内容分析详细信息并仅获取电子邮件中的邮件内容

I am writing a PHP script to get email piped to the script and save it to the database.. I have succeeded in get coming emails.. But i am still struggling with how to get rid of raw contents that comes with the email.. What technique can i use to get only the message either the text version or the html version This is the example of email i receive currently

Content preview:  Mine Mine [...]

 Content analysis details:   (-0.1 points, 5.0 required)

  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
  0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail provider
                             (techservice4real[at]gmail.com)
  0.0 HTML_MESSAGE           BODY: HTML included in message
 -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from author's
                             domain
  0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily valid
 -0.1 DKIM_VALID             Message has at least one valid DKIM or DK signature
 -0.0 RCVD_IN_MSPIKE_H2      RBL: Average reputation (+2)
                             [209.85.222.182 listed in wl.mailspike.net]
X-Spam-Flag: NO

--000000000000c1a52105822cd389
Content-Type: text/plain; charset='UTF-8'

Mine

--000000000000c1a52105822cd389
Content-Type: text/html; charset='UTF-8'

<div dir='ltr'>Mine<br></div>

--000000000000c1a52105822cd389--

This is currently the code i am using to get the email

#!/usr/local/bin/php -q
<?php 
require_once('inc/init.php');   
//chdir(dirname(__FILE__));
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
// if(strlen($email)<1) {
//     die(); 
// }
// handle email
$lines = explode("
", $email);
// empty vars
$from = "";
$to="";
$subject = "";
$headers = "";
$message = "";
$bodyContent = "";
$myBody = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
    if ($splittingheaders) {
        // this is a header
        $headers .= $lines[$i]."
";
        // 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];
        }
        if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
            $to = $matches[1];
        }
    } else {
        // not a header, but message
        $message .= $lines[$i]."
";
    }
    if (trim($lines[$i])=="") {
        // empty line, header section has ended
        $splittingheaders = false;
    }
}

$data = explode("
", $message);
mail("boomztechs@gmail.com", "You Have One new Email Piped", "A New Mail Message just Piped to you) ".$message);

Your response is highly appreciated thanks..

</div>
dongyou6847
dongyou6847 是的,我没有边界复制电子邮件的标题部分..我得到了所有其他路径。电子邮件来自,电子邮件发送,主题..这只是我有问题的身体..这就是为什么我复制身体样本..我的问题是我怎样才能摆脱所有这些原始数据前后两个电子邮件的文本和HTML版本..我希望能够只得到消息..我怎么能用PHP做到这一点?谢谢
11 个月之前 回复
dongtaijue1578
dongtaijue1578 您的示例电子邮件已删除其标头。假设这是一个管道过滤器,你要么是为了隐私/简洁而切断它们,要么是你的米尔特正在输送不完整的信息。您需要消息的Content-Type:标头中的boundary属性,以便将消息正确解析为部分。虽然对于这个特定的消息可能看起来很明显,但你不应该试图猜测它。
11 个月之前 回复
dongyu3967
dongyu3967 嗨Sammitch,谢谢你的回复..我想让你向我解释一下我不明白你的意思“示例是遗失标题”..你在谈论代码或电子邮件样本吗?
11 个月之前 回复
dsyct08008
dsyct08008 您的示例缺少标题,这是定义MIME边界的重要部分。您使用边界将消息解析为部分,每个部分都有自己的标题。w3.org/Protocols/rfc1341/7_2_Multipart.html不幸的是,PHP没有用于解析multipart的userland函数,但是有一些[可用的库]。
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问