PHP5-IMAP 'I aint got no body!'
Asked Answered
K

1

5

Here is a strange one for you.

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

I can send email messages to my mailbox, 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 send a sms message to the mailbox imap_fetchbody, it returns empty.

However, if I then read the mailbox with a email client the message is there. I do not think it is an Ipipi issue.

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

Knap answered 2/3, 2011 at 16:33 Comment(4)
Have you looked to see if the wireless carrier is forming the email headers correctly?Phony
I have, perhaps naively, assumed that if Thunderbird can read the message, then the headers must be OK.Knap
It'd help to have a sample message.Fool
Why do you use email? It is slow. Very slow. Why don't you open up a port in your PHP script? I don't know if this is possible, but it's worth a shot.Avon
F
5

When you issue

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

you're asking for the content of part 2 of the message. (That's what the third argument to imap_fetchbody means.)

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

It's hard to know without being able to see a sample message from the SMS gateway, but I'd guess that your message isn't a multipart and thus it doesn't have a part 2. What happens if you substitute a 1 for the 2 when fetching this particular message?

(In general, you'll want to look at the message structure before deciding which body part to fetch. You can use imap_fetchstructure for this.)

Fool answered 2/3, 2011 at 19:35 Comment(2)
dkarp : You are the main man! Replacing the '2' with a '1' gets it working. Also a standard email still works. My problem is that I picked the code up off the web. Having tested that it worked with a standard email I was stumped when it did not work with the sms email. I had assumed, wrongly, that '2' was the standard body part to request. Silly me. Many thanks for your help.Knap
@BillP: If this answered your question, please click on the checkmark outline to the left of the answer. It makes the solution clear to the next person with the same issue...Fool

© 2022 - 2024 — McMap. All rights reserved.