Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Unable to read text file

the mail() function

Moderators: macek, egami, gesf

Unable to read text file

Postby Gian_Piero » Mon Oct 09, 2006 8:37 am

Hi everyone willing to help !!
I tried to access a chunk of an email context, assuming the context string is in plain text format.
I wrote:
$content = imap_fetchbody($mbox,$jj,'1');

Then I tried to get a 24 character long chunk
$chunk = substr($content,0,24);

I got the error message:
ENABLE TO READ THIS

Probably there was a non-text format.
How can I check (before using the 24 character chunk) if one or all the 24 characters are NOT in text format ?

Thank you to everyone willing to help !!!
Gian_Piero
Gian_Piero
New php-forum User
New php-forum User
 
Posts: 22
Joined: Wed Oct 06, 2004 8:12 am
Location: Surfside,Florida

Postby gesf » Mon Oct 09, 2006 3:02 pm

You must probably break down the message first as it comes in multiple parts.
Example:
Code: Select all
0 multipart/mixed
   1 multipart/alternative
       1.1 text/plain
       1.2 text/html
   2 message/rfc822
       2 multipart/mixed
           2.1 multipart/alternative
               2.1.1 text/plain
               2.1.2 text/html
           2.2 message/rfc822
               2.2 multipart/alternative
                   2.2.1 text/plain
                   2.2.2 text/html
So if you want to get, for example, the Plain part of the "multipart" message, you must do:
Code: Select all
<?php $content = imap_fetchbody($mbox, $jj, "1.1"); ?>
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Gian_Piero » Tue Oct 17, 2006 9:40 am

Thank you very much for your reply.
I just wondered if I did it correct in putting the code before the fetching instruction:

0 multipart/mixed
1 multipart/alternative
1.1 text/plain
1.2 text/html
2 message/rfc822
2 multipart/mixed
2.1 multipart/alternative
2.1.1 text/plain
2.1.2 text/html
2.2 message/rfc822
2.2 multipart/alternative
2.2.1 text/plain
2.2.2 text/html

id=1;
$message = imap_fetchbody($mbox,$id,"1.1"); ## GET THE BODY OF MULTI-PART MESSAGE
print $message;

I get an error at the first line "0 multipart/mixed"

Could you tell me what did I do wrong ?
Thanks for your help
Gian Piero
Gian_Piero
New php-forum User
New php-forum User
 
Posts: 22
Joined: Wed Oct 06, 2004 8:12 am
Location: Surfside,Florida

Postby gesf » Tue Oct 17, 2006 8:23 pm

What error(s) you get !?
First, try checking if you really have a multi-part message with imap_fetchstructure(), so you can use imap_fetchbody(). Otherwise use imap_body().
You have a great example at the imap_fetchbody manual page.
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Gian_Piero » Wed Oct 18, 2006 7:48 am

Gonzalo, thanks a million !
I proceeded following your instruction to first check the structure to determine IF it is a MULTIPART and it worked just perfect !!!
Thanks again, without your great help I would have never found out about it !
Gian_Piero
Gian_Piero
New php-forum User
New php-forum User
 
Posts: 22
Joined: Wed Oct 06, 2004 8:12 am
Location: Surfside,Florida

Postby gesf » Wed Oct 18, 2006 9:59 pm

I'm glad you made it!
Any time :)
User avatar
gesf
Moderator
Moderator
 
Posts: 1718
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby Gian_Piero » Fri Jan 12, 2007 5:38 am

Hi Goncalo,
A few months ago you helped me out to read text/HTML in an email.
There is a question which has been haunting my mind for a while: is it possible to read a text/HTML from any web page source just like in an email ?
Cheers
Gian_Piero
New php-forum User
New php-forum User
 
Posts: 22
Joined: Wed Oct 06, 2004 8:12 am
Location: Surfside,Florida


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron