PHP5-IMAP "I have no body!"

Here is a strange thing.

I am using the Ipipi SMS service to send email to send control commands in a PHP script.

I can send emails to my inbox and then read and display them using PHP-IMAP commands, as in this code segment:

$overview = imap_fetch_overview($inbox,$email_number,0); $message = imap_fetchbody($inbox,$email_number,2); echo $message;

If I sent an sms message to the mailbox imap_fetchbody , it will be empty.

However, if I then read the mailbox with the mail client, there will be a message. I do not think this is the Ipipi problem.

If I do var_dump($message) , I get string(0) "" .

+5
php imap
source share
1 answer

Upon release

 $message = imap_fetchbody($inbox,$email_number,2); 

you request the content of part 2 of the message. (What the third argument to imap_fetchbody .)

 string imap_fetchbody ( resource $imap_stream , int $msg_number , string $section [, int $options = 0 ] ) 

It is difficult to find out, without being able to see an example message from the SMS gateway, but I would assume that your message is not multi-part and therefore does not have part 2. What happens if you replace 1 with 2 when you receive this particular message?

(In general, you need to look at the message structure before deciding which part of the body you want to extract. You can use imap_fetchstructure to do this.)

+5
source share

All Articles