Php imap_open()问题

Php imap_open()问题,php,Php,我试图从任何一家电子邮件服务提供商那里获得“电子邮件”,比如:雅虎、Gmail、Hotmail。但是我不能得到它。显示错误消息 以下是我的php脚本.. <?php if( $mbox = imap_open("{yoursitename.com:110/pop3/notls}INBOX", "username of mailbox", "password of mailbox")){ $path = "set path here for where the attachments a

我试图从任何一家电子邮件服务提供商那里获得“电子邮件”,比如:雅虎、Gmail、Hotmail。但是我不能得到它。显示错误消息

以下是我的php脚本..

<?php

if( $mbox = imap_open("{yoursitename.com:110/pop3/notls}INBOX", "username of mailbox", 
"password of mailbox")){
$path = "set path here for where the attachments are store";
$check = imap_mailboxmsginfo($mbox);     
function getmsg($mbox,$mid) {   
    global $charset,$htmlmsg,$plainmsg,$attachments,$from,$to,$subj,$timages,$path;
    $htmlmsg = $plainmsg = $charset = '';
    $attachments = array();
    // HEADER
    $h = imap_headerinfo($mbox,$mid);
    // add code here to get date, from, to, cc, subject...
    $date = $h->date;
    $from = $h->fromaddress;
    $to = $h->toaddress;
      $subj = htmlspecialchars($h->Subject);
    // BODY
    $s = imap_fetchstructure($mbox,$mid);
    if (!$s->parts)  // simple
    getpart($mbox,$mid,$s,0);  // pass 0 as part-number
    else {  // multipart: cycle through each part
    foreach ($s->parts as $partno0=>$p)
      getpart($mbox,$mid,$p,$partno0+1);
    }
}

function getpart($mbox,$mid,$p,$partno) {
    // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
    global 
 $htmlmsg,$plainmsg,$charset,$attachments,$partid,$last_mail_id,$patterns,$pic,
 $newstr,$c,$ok,$timages,$subj,$path;
    $patterns = array();
    $pic =  array();
    $image=array();
    $data = ($partno) ? imap_fetchbody($mbox,$mid,$partno) : imap_body($mbox,$mid);    
// simple
    if ($p->encoding==4)
    $data = quoted_printable_decode($data);
    else if ($p->encoding==3)
    $data = base64_decode($data);
    // PARAMETERS    // get all parameters, like charset, filenames of attachments, 
etc.
    $params = array();
    if ($p->parameters)
    foreach ($p->parameters as $x)
        $params[strtolower($x->attribute)] = $x->value;
    if ($p->dparameters)
    foreach ($p->dparameters as $x)
        $params[strtolower($x->attribute)] = $x->value;

    // ATTACHMENT    // Any part with a filename is an attachment,
    // so an attached text file (type 0) is not mistaken as the message.
    if ($params['filename'] || $params['name']) {
    $partid = htmlentities($p->id,ENT_QUOTES);

       // filename may be given as 'Filename' or 'Name' or both
    $filename = ($params['filename'])? $params['filename'] : $params['name'];
    // filename may be encoded, so see imap_mime_header_decode()
     $attachments[$filename] = $data;  // this is a problem if two files have same name
    //store id and filename in array
    $image[$key] = $filename;

    }
    //save the attachments in the directory
    foreach( $attachments as $key => $val){
      $fname = $key;
      $fp = fopen("$path/$fname","w");
      fwrite($fp, $val);
      fclose($fp);
    }
        // TEXT
        if ($p->type==0 && $data) {
        // Messages may be split in different parts because of inline attachments,   
// so append parts together with blank row.
        if (strtolower($p->subtype)=='plain')
            $plainmsg .= trim($data)."\n\n";
        else
            //preg_match_all('/<img[^>]+>/i',$data, $result);
            $htmlmsg .= $data."<br><br>";
            $charset = $params['charset'];  // assume all parts are same charset
        }

    // There are no PHP functions to parse embedded messages, so this just appends the 
raw source to the main message.
    else if ($p->type==2 && $data) {
    $plainmsg .= $data."\n\n";
    }
    // SUBPART RECURSION
    if ($p->parts) {
    foreach ($p->parts as $partno0=>$p2)
        getpart($mbox,$mid,$p2,$partno.'.'.($partno0+1));  // 1.2, 1.2.1, etc.
    }
}

$attachments = array();
$num_msg = imap_num_msg($mbox);
if($num_msg>0) {
    getmsg($mbox,1);
}else {
     echo "Sorry!...No Messages in MailBox...<br>";
}

//imap_delete and imap_expunge are used to delete the mail after fetching....Uncomment 
it if you want to delete the mail from mailbox
//imap_delete($mbox,1); 
//imap_expunge($mbox);
imap_close($mbox);


}else { exit ("Can't connect: " . imap_last_error() ."\n");  echo "FAIL!\n";  };


?>
有人能修好吗?

谢谢。

正如arkascha所说,yahoo.com不会在端口110上监听


Yahoo的POP3服务器位于端口110上(或带有SSL的995),如

所述,快速telnet检查表明,Yahoo.com端口110上没有POP3服务器在监听。因此,这不是代码中的错误,但您正在尝试连接到一个没有服务器侦听的服务器…相关:有一个很好的PHP类,用于在@Stecman处使用IMAP/POP,页面未加载..我将其上载到我的测试服务器,但没有显示任何内容。只是空白白页。@Babu不确定code.google.com上的php imap页面没有加载是什么意思,但是如果php配置为不显示错误,您可能会在测试服务器上看到空白白页。
Warning: imap_open() [function.imap-open]: Couldn't open stream {yahoo.com:110/pop3
/notls}INBOX in D:\xampp server\xampp\htdocs\practice\php\email.php on line 2


Fatal error: Maximum execution time of 30 seconds exceeded in D:\xampp server\xampp
\htdocs\practice\php\email.php on line 2


Notice: Unknown: Can't connect to yahoo.com,110: Timed out (errflg=1) in Unknown on 
line 0

Notice: Unknown: Can't connect to yahoo.com,110: Timed out (errflg=1) in Unknown on 
line 0


Notice: Unknown: Can't connect to yahoo.com,110: Timed out (errflg=2) in Unknown on line 0