elabuwa Posted June 7, 2011 Share Posted June 7, 2011 Hi guys, I am trying to read a set of emails. Below is my code. <?php $imap = imap_open("{mail.emailserver.com:143/notls}INBOX", "[email protected]", "password"); $message_count = imap_num_msg($imap); for ($i = 1; $i <= $message_count; ++$i) { $header = imap_header($imap, $i); $body = imap_body($imap, $i); $prettydate = date("jS F Y", $header->udate); if (isset($header->from[0]->personal)) { $personal = $header->from[0]->personal; } else { $personal = $header->from[0]->mailbox; } $email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>"; //echo "On $prettydate, $email said \"$body\".\n"; echo $body; } imap_close($imap); ?> I assume that the code is working coz when I send a normal email from outlook or what ever it displays them properly. However, for a certain set of emails it DOES display some characters but no where near anything in the message. The email reads fine in Horde/Squirrel etc. The actual email looks like Ticker Coupon Maturity B/O Price B/O Yield Mid ASW Mid Z Axe ------------------------------------------------------------------------------ FMGAU 7 01-Nov-15 103.500/104.500 6.078 /5.822 436.8 447 FMGAU 6.375 01-Feb-16 101.250/102.250 6.058 /5.811 418.9 435 FMGAU 6.875 01-Feb-18 103.250/104.250 6.266 /6.084 378.5 395 s2.165mm BUT MY PHP CODE SHOWS IT LIKE VGlja2VyIENvdXBvbiBNYXR1cml0eSAgICAgQi9PICAgUHJpY2UgICAgICBCL08gIFlpZWxkICBN aWQgQVNXIE1pZCBaIEF4ZSAgICAgDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCkZNR0FVICA3ICAg ICAgMDEtTm92LTE1ICAxMDMuNTAwLzEwNC41MDAgIDYuMDc4IC81LjgyMiAgNDM2LjggICA0NDcg ICAgICAgICAgIA0KRk1HQVUgIDYuMzc1ICAwMS1GZWItMTYgIDEwMS4yNTAvMTAyLjI1MCAgNi4w NTggLzUuODExICA0MTguOSAgIDQzNSAgICAgICAgICAgDQpGTUdBVSAgNi44NzUgIDAxLUZlYi0x OCAgMTAzLjI1MC8xMDQuMjUwICA2LjI2NiAvNi4wODQgIDM3OC41ICAgMzk1ICBzMi4xNjVtbSAN Cg== I am totally confused with this scenario. :shrug: :shrug: Can any one please help me out. :'( :'( :'( :'( :'( Cheers Ela Buwa Link to comment https://forums.phpfreaks.com/topic/238616-reading-emails-with-php/ Share on other sites More sharing options...
kenrbnsn Posted June 7, 2011 Share Posted June 7, 2011 Those email messages are encoded with Base64, to decode them use base64_decode. There should be a header in the email message telling you that the message is encoded. BTW, the decoded message is Ticker Coupon Maturity B/O Price B/O Yield Mid ASW Mid Z Axe ------------------------------------------------------------------------------ FMGAU 7 01-Nov-15 103.500/104.500 6.078 /5.822 436.8 447 FMGAU 6.375 01-Feb-16 101.250/102.250 6.058 /5.811 418.9 435 FMGAU 6.875 01-Feb-18 103.250/104.250 6.266 /6.084 378.5 395 s2.165mm Ken Link to comment https://forums.phpfreaks.com/topic/238616-reading-emails-with-php/#findComment-1226280 Share on other sites More sharing options...
elabuwa Posted June 7, 2011 Author Share Posted June 7, 2011 thank you very much Ken. :D :D Worked like magic Link to comment https://forums.phpfreaks.com/topic/238616-reading-emails-with-php/#findComment-1226290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.