Im really confused on this, i have an email that is generated from a log file, it sends an email with the contents of the log file in the body.
I done some testing as im new to imap stuff and php in general on a test gmail account, with the following code i could see the whole body of hundreds of emails without issue:
$mailbox = "xxx@gmail.com";
$mailboxPassword = "xxxx";
$mailbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", $mailbox, $mailboxPassword);
$mail = imap_search($mailbox,'ALL');
if(empty($mail)) die('No unread emails found!');
foreach ($mail as $key => $val)
{
// Retrieving message headers
$headers = imap_headerinfo($mailbox, $val);
// Retrieving subject
$subject = $headers->subject;
p.s i can echo the subject and all is returned fine
mb_internal_encoding("UTF-8");
$subject = mb_decode_mimeheader(str_replace('_', ' ', $subject));
$body_pre = imap_fetchbody($mailbox, $val, 1);
$body = $body_pre ? imap_qprint(imap_fetchbody($mailbox, $val, 2)) : imap_qprint(imap_fetchbody($mailbox, $val, 1));
if (empty($body))
{
$body = $body_pre;
}
Now the code is probably messy, i basically took over someone elses code and made it work for me, i added the if empty one because some of the bodys was returning empty, once i added that it worked fine. I know its due to Russian/French encoding so although the info displays fine the russian/french characters dont display correctly but its at least not empty
Anyway basically what i done was took the original email, forwarded it to this test account, ran that code and if i echoed out $body i could see every email body.
Now the problem occurred when i took the exact same emails, there all the same email logs from a txt file basically sent as an email, but when i ran the same query on the inbox with basically only difference they have FW: in the subject well this is what the body outputted as:
SE0yIENyYXNoIExvZyBDb250ZW50cyBCZWxvdzo8YnIgLz48YnIgLz5Vc2VyIEVtYWlsOiBBbm9u
LiAtIE5vdCBTdXBwbGllZDxhbm9uQGhvbGRlbW1hbmFnZXIuY29tPjxiciAvPkJ1aWxkIEluZm86
IDIuMC4wLjc2NjU8YnIgLz5Vc2VyIERlc2NyaXB0aW9uOiBOL0E8YnIgLz48YnIgLz5Mb2cgRmls
ZSBDb250ZW50czogPGJyIC8+PGJyIC8+MDE6MTI6MTMuMTEwIFtNYWluOjEgLSBVbml0eUJvb3Rz
dHJhcHBlci5SdW5dIDxiciAvPg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICBfX18gICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgIDxiciAvPg0KICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICggICApICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDxiciAvPg0KICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICB8IHwgLi0uICAgIF9fXyAuLS4gLi0uICAgICAuLS0uICAg
IDxiciAvPg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8IHwvICAgXCAgKCAgICkgICAn
And body_pre echoes as empty
I tried changing to this also and echoing all these and they all displayed blank
$body_pre0 = imap_fetchbody($mailbox, $val);
$body_pre = imap_fetchbody($mailbox, $val, 1);
$body_pre1 = imap_fetchbody($mailbox, $val, 1.1);
$body_pre2 = imap_fetchbody($mailbox, $val, 1.2);
$body_pre3 = imap_fetchbody($mailbox, $val, 2);
$body_pre4 = imap_fetchbody($mailbox, $val, 2.0);
$body_pre5 = imap_fetchbody($mailbox, $val, 2.1);
$body_pre6 = imap_fetchbody($mailbox, $val, 2.2);
$body_pre7 = imap_fetchbody($mailbox, $val, 2.3);
echo "Body 0: <br /><br /><br />" . $body_pre0 . "<br />";
echo "Body 1: <br /><br /><br />" . $body_pre . "<br />";
echo "Body 1.1: <br /><br /><br />" . $body_pre1 . "<br />";
echo "Body 1.2: <br /><br /><br />" . $body_pre2 . "<br />";
echo "Body 2: <br /><br /><br />" . $body_pre3 . "<br />";
echo "Body 2.0: <br /><br /><br />" . $body_pre4 . "<br />";
echo "Body 2.1: <br /><br /><br />" . $body_pre5 . "<br />";
echo "Body 2.2: <br /><br /><br />" . $body_pre6 . "<br />";
echo "Body 2.3: <br /><br /><br />" . $body_pre7 . "<br />";
Im a bit lost and would love a bit of guidance so i dont lose my mind before the new year 🙂
The email has a bunch of confidential stuff, i can add it with that all blanked out if it helps but i presume since the forwarded emails works and not the original its probably some encoding type issue or something obvious but let me know if adding that helps, most emails are huge so it would take a long time to edit all confidential info but can do if you request
that doesn’t look like garbage to me… it looks like base64 encoded html…