SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why doesn't messsage show?

    Hiya, I have been following an email client tutorial but am having trouble with viewing emails. I can get it to display the from, to, date and subject but the message and any attachments do not display. I have tried a few different things but can't get it to work. Please can someone have a look at the code for the view page and give me a clue where it is wrong. It must be a problem with the code because when I load the email account using squirrel mail I can see the message.
    PHP Code:
    <?php
        session_start
    (); //Use the registered session.
        //log into the server and get the total number of messages 
        
        
    $username $_SESSION['username'];
        
    $epw $_SESSION['password'];    

        
    $inbox imap_open("{".$emailserver."}"$username.$domain$epw);
        
    $total imap_num_msg($inbox);

    // get the message structure
    $id $_GET['id'];

    $headers imap_header($inbox$id);
    $structure imap_fetchstructure($inbox$id);
    $parsedStructure = array();
    $parts $structure->parts;

    //before we start building our multipart message handling, set some common values
    // message types
    $type = array("text""multipart""message""application""audio""image""video""other");
    // message encodings
    $encoding = array("7bit""8bit""binary""base64""quoted-printable""other");

    if (
    sizeof($parts>1))
    {
    for(
    $i=0$i<sizeof($parts); $i++)
        {
            
    $parsedStructure[$i]["pid"] = ($i+1);    
        
            
    $currentpart $parts[$i];
            if (
    $currentpart->type == "") { $currentpart->type 0; }
            
    $parsedStructure[$i]["type"] = $type[$currentpart->type] . "/" strtolower($currentpart->subtype);    
            
            if (
    $currentpart->encoding == "") { $currentpart->encoding 0; }
            
    $parsedStructure[$i]["encoding"] = $encoding[$currentpart->encoding];    
            
    $parsedStructure[$i]["size"] = strtolower($currentpart->bytes);    
            
    $parsedStructure[$i]["disposition"] = strtolower($currentpart->disposition);    

            if (
    strtolower($currentpart->disposition) == "attachment")
            {
                
    $params $currentpart->parameters;
                foreach (
    $params as $p)
                {
                    if(
    $p->attribute == "NAME")
                    {
                    
    $parsedStructure[$i]["filename"] = $p->value;    
                    break;
                    }
                }
            }
        }
        
    // now keep only the attachment information separate
    for($i=0$i<sizeof($parsedStructure); $i++)
        {
            if(
    $parsedStructure[$i]["disposition"] == "attachment")
            {
            
    $attachments[] = $parsedStructure[$i];
            }
        }
    }
    // we can now handle our Text and HTML body appropriately and prepare a listing of our attachments
    ?>

    <div id="main"><br />
    <div class="ttlhead"><h2>Read Email</h2></div>
    <br />

    <a href="compose.php?reply=<?php echo($id); ?>">Reply</a>
    <a href="delete.php?del=<?php echo($id); ?>">Delete</a>
    <a href="inbox.php">Back to Inbox </a>

    <?php
    echo '<br />
        <div class="clearfix">
        <div class="row100t">From: </div>
        <div class="row680">
        <div class="pmcont">'
    .htmlspecialchars($headers->fromaddress).'</div>
        </div></div>

        <div class="clearfix">
        <div class="row100t">Date: </div>
        <div class="row680">
        <div class="pmcont">'
    .$headers->Date.'</div>
        </div></div>

        <div class="clearfix">
        <div class="row100t">Subject: </div>
        <div class="row680">
        <div class="pmcont">'
    ;
        if (
    $headers->Subject) {
            echo 
    $headers->Subject;
        } else {
            echo 
    "No subject";
        } echo 
    '</div>
        </div></div>

        <div class="clearfix">
        <div class="row100t">Message: </div>
        <div class="row680">
        <div class="pmcont">'
    ;
        if(
    is_array($parsedStructure)) {
            for(
    $i=0$i<sizeof($parsedStructure); $i++) {
                if((
    $parsedStructure[$i]["type"] == "text/plain" || $parsedStructure[$i]["type"] == "message/rfc822") && $parsedStructure[$i]["disposition"] != "attachment"){
                    echo 
    "<p />";
                    echo 
    htmlspecialchars(stripslashes(trim(imap_fetchbody($inbox$id$parsedStructure[$i]["pid"]))));
                    echo 
    "<p />";
                }
                if(
    $parsedStructure[$i]["type"] == "text/html") {
                    echo 
    "<p />";
                    echo (
    imap_fetchbody($inbox$id$parsedStructure[$i]["pid"]));
                }
                echo 
    "</p>";
            }
        } else {
            echo 
    htmlspecialchars(stripslashes(trim(imap_body($inbox$id))));
        } echo 
    '</div>
        </div></div><br />

        <div class="clearfix">
        <div class="row100t">Attachments: </div>
        <div class="row680">
        <div class="pmcont">'
    ;
        for (
    $i=0$i<sizeof($attachments); $i++) {
            echo (
    '<li><a href=download.php?id='.$id.'&pid='.$attachments[$i]["pid"] . '&type=' $attachments[$i]["type"] . '&filename=' $attachments[$i]["filename"] . '&encoding=' $attachments[$i]["encoding"] . '>' $attachments[$i]["filename"] . ' (' ceil($attachments[$i]["size"]/1024) . ' KB)</a>');
            echo (
    '<br>');
        } echo 
    '</div>
        </div></div>'
    ;

    ?>
    Thanx

  2. #2
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump! Is anyone able to help me with this problem? I am really struggling

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Hertfordshire, England
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Nothing is jumping out in the code--you mention you are following a tutorial is it possible to get the link to this--it might help debug?

    Thanks, MH

  4. #4
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for the reply The link to the tutorial is http://www-128.ibm.com/developerwork...p-webmail.html You need to sign up to view it though.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Hertfordshire, England
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've signed up but I have to go into a couple of meetings now; so won't be able to look at this for a couple of hours. Hopefully someone else will help you in that time. If not I will look again later today. I promise
    MH

  6. #6
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx march

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Hertfordshire, England
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Tina, I really can't see anything wrong from the code you've posted but reading around the subject it *may* be something to do with how this script deals with the 'type' of e-mail:
    PHP Code:
    if(($parsedStructure[$i]["type"] == "text/plain"... 
    I've seen a few suggestions that e-mails don't always follow this pattern so maybe when you check for "text/plain" and "text/html" you're messages aren't in that format. How about if you just print it out regardless? Can you remove the type check?

    Failing that I'm not sure I can be of much more help. But in the interests of seeing this one solved (I hate not knowing) I'm more than happy to try and build it tonight and see if I have any more luck. That's assuming nobody finds you a solution in the meantime
    Cheers,
    MH

  8. #8
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx sooooo much march. I removed all the type checking code and it now works
    Last edited by tina88; Mar 22, 2007 at 16:25.

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    Hertfordshire, England
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Tina--that's great, well done!!! It might be worth getting your script to print out the types at the top of the message? It'd be nice to get the type checking in the script working. But... all that said--it works, so smiles all round
    Cheers,
    MH


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •