Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

PHP IMAP Gmail not working properly..

Links for php scripts

Moderators: macek, egami, gesf

PHP IMAP Gmail not working properly..

Postby twirap » Fri Dec 02, 2011 12:22 pm

I would like to display the body contents of an email. I have tried IMAP in php but something is VERY wrong. The IMAP isn't picking up the body of my message. It is picking up ONLY the signature in the body. So I am looking for alternative methods of reading email body contents to a webpage.

here is the original document of my email:

http://pastebin.com/WQra335P

the disclaimer/copyright blur is being grabbed by IMAP but nothing else in the body is being displayed. anyone have alternative methods of reading email from gmail or any other site that can display the contents to a webpage?

I have given up on making IMAP read it because no one has been able to figure out the problem...I ahve spent hours so I give up but here is the code...




Code: Select all
<?php
    /* connect to gmail */
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = 'username@gmail.com';
    $password = 'password';

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,'ALL');

    /* if emails are returned, cycle through each... */
    if($emails) {

        /* begin output var */
        $output = '';

        /* put the newest emails on top */
        rsort($emails);

        /* for every email... */
        foreach($emails as $email_number) {

            /* get information specific to this email */
            $overview = imap_fetch_overview($inbox, $email_number, 0);
            $message = imap_fetchbody($inbox, $email_number, 2);
            echo $message;
            echo imap_qprint($message);
            $message = imap_qprint($message);
            echo imap_8bit ($message);
            $DateFormatted = str_replace("-0500", "", $overview[0] -> date);

            /* output the email header information */
            $output .=  $overview[0] -> subject ;
            $output .=  $DateFormatted ;

            //$bodyFormatted = preg_replace("/This e-mail(.*)/","",$message);
            //$bodyFormatted = preg_replace("/Ce courriel(.*)/","",$bodyFormatted);
            /* output the email body */
            $output .=  $message;

        }

    echo $output;

    }

    /* close the connection */
    imap_close($inbox);

?>
twirap
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Dec 02, 2011 12:19 pm

Return to PHP Scripts

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