Incoming Message it is object(SSilence\ImapClient\IncomingMessage) has 5 basic properties
$imap->incomingMessage->header
$imap->incomingMessage->message
$imap->incomingMessage->attachment
$imap->incomingMessage->section
$imap->incomingMessage->structure
and one for debugging
$imap->incomingMessage->debug
It also has one public method for getting message attachments as objects
$imap->incomingMessage->getAttachments()
Header properties typically looks like
["header"]=>
object(stdClass)#3 (15) {
["subject"]=>
string(10) "Ocoto cat is in the new!"
["from"]=>
string(36) "..."
["to"]=>
string(36) "..."
["date"]=>
string(31) "Tue, 21 Mar 2017 11:02:37 +0000"
["message_id"]=>
string(37) "<[email protected]>"
["size"]=>
int(472418)
["uid"]=>
int(42243)
["msgno"]=>
int(82)
["recent"]=>
int(0)
["flagged"]=>
int(0)
["answered"]=>
int(0)
["deleted"]=>
int(0)
["seen"]=>
int(1)
["draft"]=>
int(0)
["udate"]=>
int(1490094157)
["details"]=>
object(stdClass)#4 (20) {}
}
To get the subject of the message, use $imap->incomingMessage->header->subject
To get the CC or BCC use the property
$imap->incomingMessage->header->details
It is object. Header details properties have more properties like this imap_headerinfo. If there is no property in the returned object, then it is not present in this letter. To get the CC or BCC of the message, use
$imap->incomingMessage->header->details->cc
# or
$imap->incomingMessage->header->details->bcc
# cc and bcc it is array of objects with properties [personal, adl, mailbox, host]
Message properties look like this:
["message"]=>
object(stdClass)#29 (3) {
["plain"]=>
string(16) "text message"
["info"]=>
array(2) {
[0]=>
object(stdClass)#27 (2) {
["structure"]=>
object(stdClass)#28 (11) {
["type"]=>
int(0)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "PLAIN"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["bytes"]=>
int(20)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#33 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
}
}
["body"]=>
string(16) "text message"
}
[1]=>
object(stdClass)#30 (2) {
["structure"]=>
object(stdClass)#31 (11) {
["type"]=>
int(0)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "HTML"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["bytes"]=>
int(72)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#34 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
}
}
["body"]=>
string(56) "<HTML><BODY><br><br><br>html text message<br></BODY></HTML>"
}
}
["html"]=>
string(56) "<HTML><BODY><br><br><br>html text message<br></BODY></HTML>"
}
To get info on the message $imap->incomingMessage->message->info Is an array. It will allways return an array
To get the body of the message $imap->incomingMessage->message->html and $imap->incomingMessage->message->plain Are auto generated by the client. This allows you to have an html and a plain text version of the email
Attachment properties it is array object. If the letter has attachments, then its return will look like as follows
["attachment"]=>
array(2) {
[0]=>
object(stdClass)#18 (2) {
["structure"]=>
object(stdClass)#19 (13) {
["type"]=>
int(5)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "JPEG"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["bytes"]=>
int(237916)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(10) "attachment"
["ifdparameters"]=>
int(1)
["dparameters"]=>
array(1) {
[0]=>
object(stdClass)#25 (2) {
["attribute"]=>
string(8) "filename"
["value"]=>
string(12) "Location.jpg"
}
}
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#24 (2) {
["attribute"]=>
string(4) "name"
["value"]=>
string(12) "Location.jpg"
}
}
}
["body"]=>string(173862) ""
... and next object ...
[1]=>
object(stdClass)#18 (2) {}
The a ttachment object has 2 basic properties. $imap->incomingMessage->attachment[0]->structure and $imap->incomingMessage->attachment[0]->body Body properties contains an attachment.
Section properties it is array sections of which the letter consists.
["section"]=>
array(5) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "3"
[5]=>
string(3) "1.1"
[7]=>
string(3) "1.2"
}
Structure propertie is the complete structure of the email
Debug propertie can be used for debugging
Attachments can be retrieved as IncomingMessageAttachment objects, which provides a better API for accessing attachment data and is accessed as follows:
$attachments = $imap->incomingMessage->getAttachments();
The attachment object has three basic methods: getName(); getBody() and getRaw().
foreach ($attachments as $attachment)
{
print $attachment->getName(); // outputs the name of the attachment
print $attachment->getBody(); // outputs the contents of the attachment
var_dump($attachment->getRaw()); // outputs the raw attachment array - see the attachments property above
}