title: How to resolve error "Fatal error: Call to a member function str_get_html() on a non-object"?
body: <p>I am making a function to download mail data in my DB.Here is my code :</p>
  
  <pre><code>include('simple_html_dom.php');
  $html = new simple_html_dom();
  global $html;
  function getArraySubject($stream,$subject){
  
  $array = imap_search($stream, $subject);
  return $array ;
  }
  // $domain 0 = any domeain from which we are receiving mails
  //$case = subject number for ex :- Query, Potential.....
  function getDataFromHTML($subjectArray, $domain = 0, $case = 1)
  {
  $completeArray = array();
  if ($domain == 0 &amp;&amp; $case == 1) {
  rsort($subjectArray);
  
  foreach($subjectArray as $email_id){
  
   $body = imap_qprint(imap_body($stream,$email_id));
      $my_file = 'mail-data.txt';
      file_put_contents($my_file, $body);
      $html = file_get_contents($my_file, true); 
      $htmlData = $html-&gt;str_get_html($body);
      $tds = $htmlData-&gt;find('table',3)-&gt;find('td');
      $num = null;
      $i = 0 ;
       foreach($tds as $td){
        $completeArray['magicbricks']['case1'][$i] = $td-&gt;innertext; 
                    $i++;          
              }
  }
  }
  return $completeArray;
  }
  </code></pre>
  
  <p>I am getting an error "Fatal error: Call to a member function str_get_html() on a non-object in line no. 25".</p>
  
  <p>How to resolve this issue? please help.</p>
  
  <p>And this is my second file where I am calling above mentioned function.</p>
  
  <pre><code>error_reporting(E_ALL);
  ini_set('display_errors', 1);
  include('functions.php');
  // Configure your imap mailboxes
  $mailboxes = array(
     array(
      'label'     =&gt; 'Label',
      'mailbox'   =&gt; '{imap.gmail.com:993/imap/ssl}INBOX',
      'username'  =&gt; 'abc@uabc.com',
      'password'  =&gt; 'abc246'
  )
     );
  
  foreach ($mailboxes as $current_mailbox) {
  
  // Open an IMAP stream to our mailbox
  $stream = @imap_open($current_mailbox['mailbox'], $current_mailbox['username'],      $current_mailbox['password']);
  
  if (!$stream) { 
  ?&gt;
      &lt;p&gt;Could not connect to: &lt;?php echo $current_mailbox['label']?&gt;. Error: &lt;?php echo imap_last_error()?&gt;&lt;/p&gt;
  &lt;?php
  } else {
      $sub1 = 'SUBJECT "Query" FROM "magicbricks.com"';
  
  
  $array1 = getArraySubject($stream,$sub1);
  
  print_r($array1);
  
      if (!count($array1)){
      ?&gt;
          &lt;p&gt;No e-mails found.&lt;/p&gt;
      &lt;?php
      } else {
  
          $result = getDataFromHTML($array1, $domain = 0, $case = 1);
  
  print_r($result);
  
      } 
      } 
  
      // Close our imap stream.
      imap_close($stream); 
  
  } // end foreach 
  </code></pre>