getContent() isn't working as expected?

Hi, this is my working code:

$mail = new Imap([
    'host'     => '',
    'port' => 993,
    'user'     => '',
    'password' => '123',
    'ssl' => 'SSL'

echo $mail->countMessages() . " messages found\n";

foreach ($mail as $message) {
echo $message->from.'</br>';
echo $message->subject.'</br>';

Im later using this loop to store the data on a DB.
But if i try to access the body or full source of the email, can’t find a way to do it.

I’ve tried:

Also tried doing a loop with $message->getParts() and then $part->getRawContent().

Particularly with $message->getContent() i get Undefined array key 0.

My intention is to at least save full email source (the whole plain source) in a DB (or in a .txt file on my server).

On a second intention, would be to just store the whole text/html part on my DB.

Any pointers on how to do it?


The document here suggests using “foreach” statement like below:

foreach ($mail as $messageNum => $message) {
    // do stuff ...

Or the other way would be like the below:

$totalMessages = $mail->countMessages();

for(int $index = 0; $index < $totalMessages; $index++)
  $message = $mail->getMessage($index);
  echo $message->getSubject() . '<br />';
  echo $message->getContent() . '<br />';

I hope it helps.