Jump to content

error get gmail message body


fgtsai0418

Recommended Posts

somebody help check what's wrong is it?
<?
$authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}";
$user="name@gmail.com";
$pass="pwd";
$mbox=imap_open( $authhost, $user, $pass )
/* grab emails */
$emails = imap_search($mbox , "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($mbox,$email_number,0);
$message = imap_fetchbody($mbox,$email_number,2);
/* output the email header information */
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
/* close the connection */
imap_close($mbox);
?>
Link to comment
Share on other sites

what do you suspect to be wrong here?

Link to comment
Share on other sites

We don't know which line is line 21.

 

You forgot a semi-colon on this line:

 

$mbox=imap_open( $authhost, $user, $pass )

So I'll assume that line 21 is this:

 

$emails = imap_search($mbox , "ALL");
Link to comment
Share on other sites

Thank You, Foxy.

New problem on line 26

 

Fatal error: Maximum execution time of 30 seconds exceeded in C:AppServwwwg.php

 

<?

$authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}";
$user="name@gmail.com";
$pass="pwd";
$mbox=imap_open( $authhost, $user, $pass );
/* grab emails */
$emails = imap_search($mbox , "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($mbox,$email_number,0);
$message = imap_fetchbody($mbox,$email_number,2);
/* output the email header information */
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
/* close the connection */
imap_close($mbox);
?>
Link to comment
Share on other sites

Unfortunately, I can't tell what's causing the program to take so long. I don't think there's an infinite loop so perhaps the imap connection is taking too long to respond.

 

Try removing some of the lines of code until this error stops occurring.

Link to comment
Share on other sites

do a count on the number of emails

 

echo count($emails)

 

there are a couple of ways to handle this if timing out is the issue, and you want to request smaller batches of emails

  1. pagination - using a query string, you can define a starting/offset index and a limit on how many emails to show at once. this way the user will not have to be loading every image at once, and will only view N (limit) emails at once.
  2. lazy loading - using AJAX, you can load more emails as needed, sending an offeset to the backend to tell it where to start getting the next batch of N (limit) emails)

 

both options require an intermediate skillset in order to implement.

Link to comment
Share on other sites

I use imap function to open my Gmail
It works, but information is wrong. Because my gmail have 108 mails.
But it only show "0"
===================================
Date: Fri, 2 Aug 2013 10:09:52 +0800Driver: pop3Mailbox: {gmail-pop.l.google.com:995/pop3/notls/ssl/novalidate-cert/user="name@gmail.com"}INBOXMessages: 0Unread: 0Size: 0
=================================
<?php
$authhost="{pop.gmail.com:995/pop3/ssl/novalidate-cert}";
$user="name@gmail.com";
$pass="pwd";
$mbox=imap_open( $authhost, $user, $pass );
{
$check = imap_mailboxmsginfo($mbox);
echo "Date: " . $check->Date . "<br />n" ;
echo "Driver: " . $check->Driver . "<br />n" ;
echo "Mailbox: " . $check->Mailbox . "<br />n" ;
echo "Messages: " . $check->Nmsgs . "<br />n" ;
echo "Unread: " . $check->Unread . "<br />n" ;
echo "Size: " . $check->Size . "<br />n" ;
imap_close($mbox);
}
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...