简体   繁体   English

将电子邮件正文输出转换为PHP中的TEXT文件

[英]Convert email body output to to TEXT file in PHP

I want to convert the following email to a txt file using PHP script. 我想使用PHP脚本将以下电子邮件转换为txt文件。 im using pipe to mail function but getting gibberish when running the script. 即时通讯使用管道到邮件功能,但运行脚本时变得乱码。

#!/usr/bin/php -q
<?
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */  
$fdw = fopen("/home/mrsirajali/pipemail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */
?>

getting the following output 得到以下输出

From ****@arbtradersignals.com Sun Mar 01 13:00:44 2015
Received: from [84.19.34.200] (port=54307 helo=wintest2)
    by **********.prod.phx3.secureserver.net with esmtpsa (TLSv1:AES256-SHA:256)
    (Exim 4.84)
    (envelope-from <******@arbtradersignals.com>)
    id 1YSA2e-0002E3-Gc
    for *******@arbtradersignals.com; Sun, 01 Mar 2015 13:00:44 -0700
Message-ID: <c76708cf$20150301200044@wintest2>
User-Agent: MetaTrader 4 Terminal
MIME-Version: 1.0
From: "=?UTF-8?B?RXhwZXJ0IEFkdmlzb3I=?="
 <*****@arbtradersignals.com>
To: "=?UTF-8?B?QXJidHJhZGVyIFNpZ25hbHM=?="
 <*****@arbtradersignals.com>
Subject: =?UTF8?B?QXJidHJhZGVyU2lnbmFscyBDVVJSRU5UIE9QRU4gUE9TSVRJT05TICAjU0lHMQ==?=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64

ClBhaXIgfCBEaXJlY3Rpb24gfCBFbnRyeSB8IFNMIHwgVFAKClVTREpQWSB8IEJVWSB8IDExOS40
MCB8IDExNy43NiB8IDEyMC40OApVU0RDSEYgfCBCVVkgfCAwLjk1MTMgfCAwLjkzNjUgfCAwLjk2
MDEKVVNEQ0FEIHwgQlVZIHwgMS4yNTAxIHwgMS4yMzAwIHwgMS4yNjQ0CkdCUEpQWSB8IEJVWSB8
IDE4My43MiB8IDE4Mi42MCB8IDE4Ni4wOApFVVJKUFkgfCBTRUxMIHwgMTM0LjUyIHwgMTM2LjIy
IHwgMTMyLjk5CgpUb3RhbCBPcGVuIFBvc2l0aW9ucyA9IDU=

content of original email . 原始电子邮件的内容。

New pending orders 新的待处理订单

Pair | 配对| Direction | 方向| Entry | 进入| SL | SL | TP | TP | Expiration 期满

USDCHF | USDCHF | BUYSTOP | 求购| 0.9513 | 0.9513 | 0.9365 | 0.9365 | 0.9581 | 0.9581 | 2015.02.26 23:59 2015.02.26 23:59

USDCAD | USDCAD | BUYSTOP | 求购| 1.2501 | 1.2501 | 1.2300 | 1.2300 | 1.2638 | 1.2638 | 2015.02.26 23:59 2015.02.26 23:59

EURUSD | EURUSD | SELLSTOP | 卖出| 1.1330 | 1.1330 | 1.1488 | 1.1488 | 1.1222 | 1.1222 | 2015.02.26 23:59 2015.02.26 23:59

EURJPY | 欧元兑日元| SELLSTOP | 卖出| 134.52 | 134.52 | 136.22 | 136.22 | 133.42 | 133.42 | 2015.02.26 23:59 2015.02.26 23:59

Total Pending Orders=4 待处理订单总数= 4

That's not gibberish, that's the contents of the email. 那不是垃圾,那是电子邮件的内容。 If you want to decode the content-transfer-encoding, just feed the body to a base64 decoder. 如果要解码内容传输编码,只需将主体馈送到base64解码器。 In the general case, you need (a library with) a good understanding of MIME structures. 在一般情况下,您需要(具有的库)对MIME结构有很好的了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM