fgtsai0418 Posted July 29, 2013 Share Posted July 29, 2013 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 More sharing options...
birbal Posted July 29, 2013 Share Posted July 29, 2013 what do you suspect to be wrong here? Link to comment Share on other sites More sharing options...
fgtsai0418 Posted July 30, 2013 Author Share Posted July 30, 2013 Parse error: syntax error, unexpected T_VARIABLE in C:AppServwwwg.php on line 21 Link to comment Share on other sites More sharing options...
Ingolme Posted July 30, 2013 Share Posted July 30, 2013 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 More sharing options...
fgtsai0418 Posted July 30, 2013 Author Share Posted July 30, 2013 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 More sharing options...
Ingolme Posted July 30, 2013 Share Posted July 30, 2013 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 More sharing options...
justsomeguy Posted July 30, 2013 Share Posted July 30, 2013 Check how many messages it is returning. You might be trying to loop through too many messages in 30 seconds. Link to comment Share on other sites More sharing options...
fgtsai0418 Posted July 31, 2013 Author Share Posted July 31, 2013 Hi Moderator How can I fix it, if I have10 mails or 100 mails? How to setup, only unread mail? Link to comment Share on other sites More sharing options...
thescientist Posted July 31, 2013 Share Posted July 31, 2013 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 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. 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 More sharing options...
justsomeguy Posted July 31, 2013 Share Posted July 31, 2013 Check the manual for imap_search, right now you're telling it to retrieve all messages. http://www.php.net/manual/en/function.imap-search.php Link to comment Share on other sites More sharing options...
fgtsai0418 Posted August 2, 2013 Author Share Posted August 2, 2013 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 More sharing options...
fgtsai0418 Posted August 2, 2013 Author Share Posted August 2, 2013 case close Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now