imap_open() Issue
<p>I'm trying to get 'email message' from any Email Service Provider, like: yahoo, Gmail, Hotmail. But I can't get it. It's show error message.</p>

<p><strong>Following is my php script..</strong></p>

<pre><code>&lt;?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-&gt;date;
    $from = $h-&gt;fromaddress;
    $to = $h-&gt;toaddress;
      $subj = htmlspecialchars($h-&gt;Subject);
    // BODY
    $s = imap_fetchstructure($mbox,$mid);
    if (!$s-&gt;parts)  // simple
    getpart($mbox,$mid,$s,0);  // pass 0 as part-number
    else {  // multipart: cycle through each part
    foreach ($s-&gt;parts as $partno0=&gt;$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-&gt;encoding==4)
    $data = quoted_printable_decode($data);
    else if ($p-&gt;encoding==3)
    $data = base64_decode($data);
    // PARAMETERS    // get all parameters, like charset, filenames of attachments, 
etc.
    $params = array();
    if ($p-&gt;parameters)
    foreach ($p-&gt;parameters as $x)
        $params[strtolower($x-&gt;attribute)] = $x-&gt;value;
    if ($p-&gt;dparameters)
    foreach ($p-&gt;dparameters as $x)
        $params[strtolower($x-&gt;attribute)] = $x-&gt;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-&gt;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 =&gt; $val){
      $fname = $key;
      $fp = fopen("$path/$fname","w");
      fwrite($fp, $val);
      fclose($fp);
    }
        // TEXT
        if ($p-&gt;type==0 &amp;&amp; $data) {
        // Messages may be split in different parts because of inline attachments,   
// so append parts together with blank row.
        if (strtolower($p-&gt;subtype)=='plain')
            $plainmsg .= trim($data)."\n\n";
        else
            //preg_match_all('/&lt;img[^&gt;]+&gt;/i',$data, $result);
            $htmlmsg .= $data."&lt;br&gt;&lt;br&gt;";
            $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-&gt;type==2 &amp;&amp; $data) {
    $plainmsg .= $data."\n\n";
    }
    // SUBPART RECURSION
    if ($p-&gt;parts) {
    foreach ($p-&gt;parts as $partno0=&gt;$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&gt;0) {
    getmsg($mbox,1);
}else {
     echo "Sorry!...No Messages in MailBox...&lt;br&gt;";
}

//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";  };


?&gt;
</code></pre>

<p><strong>error message:</strong> </p>

<pre><code>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
</code></pre>

<p>Can anyone fix it?<br>
Thanks.</p>
