Php reading email from pop

点点圈 提交于 2020-02-07 19:54:45

问题


this is my code:

  if ($mbox=imap_open( "{" . $mailserver . ":" . $port . "}INBOX", $user, $pass )) 
 {  echo "Connected\n"; 
 } else { exit ("Can't connect: " . imap_last_error() ."\n");  echo "FAIL!\n";  }; 

 if ($hdr = imap_check($mbox)) {
  $msgCount = $hdr->Nmsgs;
  echo "Ci sono ".$msgCount." mail";
} else {
  echo "Failed to get mail";

}

$connection=$mbox;
$result = imap_search($connection, 'UNSEEN');
  $output='';

 foreach($result 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;

imap_close($mbox); 

The problem is that the script is too low and I have returned Maximum execution time of 30 seconds exceeded.

How can I do? In my mailbox I have much mail (20 unread).

The problem is that when I do imap_search UNSEEN it return me all the mail, also the read mail. So UNSEEN option don't work. The mailbox is yahoo and in my box I have 990 mails and 1 unread. The problem is that it return me that 990 are unreaded but it is not true...only 1 is unreaded!

What may be the problem? Thanks.


回答1:


You can alter the max_execution time in PHP, however you should try to profile what makes your application so slow.

Does the error message give you any aditional hints, or do you know if the IMAP server is slow?



来源:https://stackoverflow.com/questions/6707950/php-reading-email-from-pop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!