SSilence / php-imap-client

a easy solution for simple IMAP email access in php
MIT License
268 stars 136 forks source link

How can I get only the message body #183

Closed ZoTyA1975 closed 7 years ago

ZoTyA1975 commented 7 years ago

Hello,

I'd like to get only the body from a message (the _body part). How can I do that?

`SSilence\ImapClient\SubtypeBody Object ( [charset] => iso-8859-2 [_structure:SSilence\ImapClient\Section:private] => stdClass Object ( [type] => 0 [encoding] => 1 [ifsubtype] => 1 [subtype] => PLAIN [ifdescription] => 0 [ifid] => 0 [lines] => 18 [bytes] => 306 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => CHARSET [value] => ISO-8859-2 )

                [1] => stdClass Object
                    (
                        [attribute] => FORMAT
                        [value] => flowed
                    )

            )

    )

[_body:SSilence\ImapClient\Section:private] => xy wrote:

blabla )`

anielka commented 7 years ago

$mail->message->html

sergey144010 commented 7 years ago

or $mail->message->plain

mattparksjr commented 7 years ago

Closed as solved.

geri777 commented 6 years ago

$mail->message->plain ... results in an error: Undefined property: stdClass::$plain

$mail->message->html ... returns the complex object above (see question) - no idea how to get the html from this object. This question is not answered in my opinion

geri777 commented 6 years ago

DISCOVERY 1: $mail->message->plain is wrong, it's $mail->message->text

geri777 commented 6 years ago

DISCOVERY 2: $mail->message->html->__get('body') ... will give you the html body of the email.

$mail->message->text->__get('body') ... will give you the text body of the email.

NOTE: You have to check if ->html is an object (same for ->text), because each of them can be null and then __get() would cause a fatal error.