title: Fatal error: Call to undefined function imap_open()
body: <p>I am trying to read emails using php,i am using below code but its shoeing an error <code>Fatal error: Call to undefined function imap_open() in /testpage2/testmail.php on line 18</code> can anyone guide me.thanks</p>
  
  <pre><code>&lt;?php
  $codes = array("7bit","8bit","binary","base64","quoted-printable","other");
  $stt = array("Text","Multipart","Message","Application","Audio","Image","Video","Other");
  
  $pictures = 0;
  $html = "";
  
  # Connect to the mail server and grab headers from the mailbox
  
  $mail = imap_open('{mail.xxxxxxxx.com:110/pop3}', 'xxxxxx@xxxxxxxx.com', 'xxxxxxxxx');
  $headers = imap_headers($mail);
  
  # loop through each email
  
  for ($n=1; $n&lt;=count($headers); $n++) {
          $html .=  "&lt;h3&gt;".$headers[$n-1]."&lt;/h3&gt;&lt;br /&gt;";
  
  # Read the email structure and decide if it's multipart or not
  
          $st = imap_fetchstructure($mail, $n);
          $multi = $st-&gt;parts;
          $nparts = count($multi);
          if ($nparts == 0) {
                  $html .=  "* SINGLE part email&lt;br&gt;";
          } else{
                  $html .=  "* MULTI part email&lt;br&gt;";
          }
  
  # look at the main part of the email, and subparts if they're present
  
          for ($p=0; $p&lt;=$nparts; $p++) {
                  $text =imap_fetchbody($mail,$n,$p);
                  if ($p ==  0) {
                          $it = $stt[$st-&gt;type];
                          $is = ucfirst(strtolower($st-&gt;subtype));
                          $ie = $codes[$st-&gt;encoding];
                  } else {
                          $it = $stt[$multi[$p-1]-&gt;type];
                          $is = ucfirst(strtolower($multi[$p-1]-&gt;subtype));
                          $ie = $codes[$multi[$p-1]-&gt;encoding];
                  }
  
  # Report on the mimetype
  
                  $mimetype = "$it/$is";
                  $html .=  "&lt;br /&gt;&lt;b&gt;Part $p ... ";
                  $html .=  "Encoding: $ie for $mimetype&lt;/b&gt;&lt;br /&gt;";
  
  # decode content if it's encoded (more types to add later!)
  
                  if ($ie == "base64") {
                          $realdata = imap_base64($text);
                          }
                  if ($ie == "quoted-printable") {
                          $realdata = imap_qprint($text);
                          }
  
  # If it's a .jpg image, save it (more types to add later)
  
                  if ($mimetype == "Image/Jpeg") {
                          $picture++;
                          $fho = fopen("imx/mp$picture.jpg","w");
                          fputs($fho,$realdata);
                          fclose($fho);
                          # And put the image in the report, limited in size
                          $html .= "&lt;img src=/demo/imx/mp$picture.jpg width=150&gt;&lt;br /&gt;";
                  }
  
  # Add the start of the text to the message
  
                  $shorttext = substr($text,0,800);
                  if (strlen($text) &gt; 800) $horttext .= " ...\n";
                  $html .=  nl2br(htmlspecialchars($shorttext))."&lt;br&gt;";
          }
  }
  
  # report results ...
  
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Reading a Mailbox including multipart emails from within PHP&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Mailbox Summary ....&lt;/h1&gt;
  &lt;?= $html ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>