dongmibeng5885
2014-02-21 14:37 阅读 65
已采纳

使用PHP抓取电子邮件

I have a script which should scrap selected email from the inbox. Everything works except BODY. Subject, date, sender and etc.. were scraped without problems but the body were returned like this:

VG9kYXkncyBGcmVlIGFuZCBCYXJnYWluIEJvb2tzCgpVcGRhdGUgUHJlZmVyZW5jZXM6ICBodHRw Oi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9wcmVmZXJlbmNlcz9oPTZjNTgxNDEyYjkzMTdiMWZlNjc1 ZDcwNDFjODJhYTc5Ckludml0ZSBGcmllbmRzOiBodHRwOi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9p bnZpdGU/aD02YzU4MTQxMmI5MzE3YjFmZTY3NWQ3MDQxYzgyYWE3OQpVbnN1YnNjcmliZTogaHR0 cDovL3d3dy5ib29rZ29yaWxsYS5jb20vdW5zdWJzY3JpYmU/aD02YzU4MTQxMmI5MzE3YjFmZTY3 NWQ3MDQxYzgyYWE3OQoKQWxsIHByaWNlcyB3ZXJlIHZlcmlmaWVkIGJ5IEJvb2tHb3JpbGxhIHBy aW9yIHRvIHRoaXMgZW1haWwgYmVpbmcgc2VudCwgYnV0IHByaWNlcyBtYXkgY2hhbmdlIHdpdGhv dXQgbm90aWNlIHNvIHBsZWFzZSB2ZXJpZnkgdGhhdCB0aGUgYm9vayBpcyBzdGlsbCBmcmVlIG9y IGJhcmdhaW4gcHJpY2VkIGJlZm9yZSBjb25maXJtaW5nIHlvdXIgb3JkZXIuIFNvbWUgYm9va3Mg bWF5IG5vdCBiZSBmcmVlIG91dHNpZGUgdGhlIFVuaXRlZCBTdGF0ZXMuIFdlIHdlbGNvbWUgeW91 ciBmZWVkYmFjaywgc28gcGxlYXNlIHJlcGx5IHRvIHRoaXMgZW1haWwgaWYgeW91IGhhdmUgYW55 IGNvbW1lbnRzIG9yIHN1Z2dlc3Rpb25zIHlvdSB3b3VsZCBsaWtlIHRvIHNoYXJlIHdpdGggdXMu CgoKCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCg0KRG9uJ3Qg bWlzcyB0aGlzIEJFU1QgUFJJQ0UgRVZFUiBvbiBEZWJiaWUgTWFjb21iZXIncyBjbGFzc2ljIERl Y2VtYmVyIDIwMTMgcmVsZWFzZSE8YnIgLz48YnIgLz5GcmllbmRzLS1BbmQgVGhlbiBTb21lPGJy IC8+KERlYmJpZSBNYWNvbWJlciBDbGFzc2ljcykNCkJ5IERlYmJpZSBNYWNvbWJlcjxiciAvPjxi ciAvPjY3JSBQcmljZSBDdXQgVGhpcyBXZWVrIQ0KDQoqKioqKiBTVEFSUkVEIFRJVExFICoqKioq CgogT25lIG9mIGFjY2xhaW1lZCBhdXRob3IgRGViYmllIE1hY29tYmVy4oCZcyBjbGFzc2ljIG5v dmVscywgdGhpcyB0ZW5kZXIgc3Rvcnkgb2YgdHdvIHBlb3BsZSBkYXJpbmcgdG8gYmUgbW9yZSB0 aGFuIOKAnGp1c3QgZnJpZW5kc+KAnSBpcyBhdmFpbGFibGUgZm9yIHRoZSBmaXJzdCB0aW1lIGlu IHRoZSBLaW5kbGUgc3RvcmUhDQoNClRvZGF5J3MgQmFyZ2FpbiBQcmljZTogJDAuOTkNCg0KR2V0 IEl0IE5vdw0KaHR0cDovL3d3dy5ib29rZ29yaWxsYS5jb20vbGluaz9sPWh0dHAlM0ElMkYlMkZ

And I have no idea why is it? This is a code I'm using:

$inbox_details = $this->email_main->getInboxDetails($data['inbox_id']); // select inbox data by inbox id
    $message_id = $inbox_details['last_sended_email_id'] + 1;

    $imap = imap_open('{'. $data['inbox_data']['inbox_server'] .'}INBOX', ''. $data['inbox_data']['inbox_email'] .'', ''. $data['inbox_data']['inbox_password'] .''); 
    if (!$imap)
        $this->email_main->insertError(imap_last_error(), $data['inbox_data']['id']);

    $header = imap_header($imap, $message_id);
    $message = array(
        'subject' => $header->subject,
        'fromname' => $header->fromaddress,
        'fromaddress' => $header->from[0]->mailbox.'@'.$header->from[0]->host,
        'toaddress' => $header->toaddress,
        'date' => $header->date,
        'timestamp' => $header->udate,
        'body' => imap_qprint(imap_fetchbody($imap, $message_id, 2)), // $message_id = 1
    );

any ideas folks?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    donglanying3855 donglanying3855 2014-02-21 14:39

    Your content is encoded in base64.

     base64_decode($content);
    

    Will decode it :)

    Edit: Decoded with http://www.base64decode.org/ to get 'Today's Free and Bargain Books'

    点赞 评论 复制链接分享

相关推荐