I have problem with reading email. While reading email from server it prints some like,

" --0016e6434b7e7427ab0489da3bab Content-Type: text/plain; charset=ISO-8859-1 this is just test "

And the actually message body of mail is "this is test"

What's the problem ?

Please help


THANKS.

Member Avatar for Zagga

Hi vizz,

What is generating the email and what are you using to read it?


Zagga

paste your code so we can help you

paste your code so we can help you

<table width="80%" border="1" bgcolor="#999999">
<tr>
<td>
<?php
    $imap = imap_open("host:143}INBOX", "username", "pass");
    $message_count = imap_num_msg($imap);

    for ($i = 1; $i <= $message_count; ++$i) {
        $header = imap_header($imap, $i);
        $body = trim(substr(imap_body($imap, $i), 0, 100));
        $prettydate = date("jS F Y", $header->udate);

        if (isset($header->from[0]->personal)) {
            $personal = $header->from[0]->personal;
        } else {
            $personal = $header->from[0]->mailbox;
        }

        $email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
        echo "$email said \"$body\".\n<br><br><br><br>";


    }

    imap_close($imap);

?>
</td>
</tr>
</table>

***********************************************************************
OUTPUT
***********************************************************************

vizz said "--0016e6434b7e7427ab0489da3bab Content-Type: text/plain; charset=ISO-8859-1 this is just test".

vizz said "--00c09f97225f2db9450489eaebfe Content-Type: text/plain; charset=ISO-8859-1 Now you have an idea".

vizz said "--00c09f97225ff793aa0489eb3712 Content-Type: text/plain; charset=ISO-8859-1 The underlying libra".

vizz said "--0016e64c246ee10c2a0489eaf299 Content-Type: text/plain; charset=ISO-8859-1 Note that I strongly".

vizz said "--00c09f93ddc46bace40489eaef4e Content-Type: text/plain; charset=ISO-8859-1 If you do not yet kn".

vizz said "--0016362848c2dc49960489eaf3a4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encod".

vizz said "--0016361e7cd8d95ff20489eaf0a8 Content-Type: text/plain; charset=ISO-8859-1 And if you are on a".

*************************************************************************************************************

I want to display message but the line is added automatically before message
i.e."--0016e6434b7e7427ab0489da3bab Content-Type: text/plain; charset=ISO-8859-1"

How to remove this line?

There is nice inbox "Nameko Webmail" just of three php files, 1 .js file and one .css file.
It is nice script of three pages. Can anyone explain how to redesign it's display?

Member Avatar for Zagga

If you have questions about commercial software, I suggest you contact the writer of the software, they know more about the code than anyone.

In response to your original querie though, it looks like all of the results have the same amount of text that you don't want. If you chop off the first 76 characters of each string you will be left with just the text you want.


Zagga

I have problem with my coding

<table width="80%" border="1" bgcolor="#999999">
<tr>
<td>
<?php
$imap = imap_open("host:143}INBOX", "username", "pass");
$message_count = imap_num_msg($imap);

for ($i = 1; $i <= $message_count; ++$i) {
$header = imap_header($imap, $i);
$body = trim(substr(imap_body($imap, $i), 0, 100));
$prettydate = date("jS F Y", $header->udate);

if (isset($header->from[0]->personal)) {
$personal = $header->from[0]->personal;
} else {
$personal = $header->from[0]->mailbox;
}

$email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
echo "$email said \"$body\".\n<br><br><br><br>";


}

imap_close($imap);

?>
</td>
</tr>
</table>

I have problem with red line[$body = trim(substr(imap_body($imap, $i), 0, 100));]

trim function does not work properly. First message shows ,"--0016e64c246ee10c2a0489eaf299 Content-Type: text/plain; charset=ISO-8859-1" before message

Member Avatar for Zagga

Hi vizz,

Currently, the substr function is returning 100 characters from the start of the string.

Try using . . .

$body = trim(substr(imap_body($imap, $i), 75));

This should return everything except the first 76 characters of the string.


Zagga

Hi vizz,

Currently, the substr function is returning 100 characters from the start of the string.

Try using . . .

$body = trim(substr(imap_body($imap, $i), 75));

This should return everything except the first 76 characters of the string.


Zagga

Thanks it works , but now it prints message again as follows,

"
vizz said "1 Now you have an idea what *imap_header()* returns, it is time to get down to business and use it. The script we are going to create loops through each message in the inbox, printing out the first 100 characters of body text for each message as it goes. To do this we are going to enlist the help of two new functions: *imap_num_msg()* and *imap_body()*, which return the number of messages in the mail box and the contents of a specific message respectively. --00c09f97225f2db9450489eaebfe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Now you have an idea what=A0imap_header()=A0returns, = it is time to get down to business and use it. The script we are going to c= reate loops through each message in the inbox, printing out the first 100 c= haracters of body text for each message as it goes. To do this we are going= to enlist the help of two new functions:=A0imap_num_msg()=A0and= =A0imap_body(), which return the number of messages in the mail bo= x and the contents of a specific message respectively. --00c09f97225f2db9450489eaebfe--".

"

And letters between * * are italic returning as simple text.

imap_header() this results as *imap_header()*


can you tell me the proper way for reading contents of email?

Thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.