我想提出一个功能来下载我DB.Here邮件数据是我的代码:如何解决错误“致命错误:调用一个非对象的成员函数str_get_html()”?
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 && $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->str_get_html($body);
$tds = $htmlData->find('table',3)->find('td');
$num = null;
$i = 0 ;
foreach($tds as $td){
$completeArray['magicbricks']['case1'][$i] = $td->innertext;
$i++;
}
}
}
return $completeArray;
}
我得到一个错误“致命错误:调用一个成员函数str_get_html()非对象上第25行“。
如何解决此问题?请帮忙。
这是我第二个文件,我在上面提到的函数。
error_reporting(E_ALL);
ini_set('display_errors', 1);
include('functions.php');
// Configure your imap mailboxes
$mailboxes = array(
array(
'label' => 'Label',
'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX',
'username' => '[email protected]',
'password' => '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) {
?>
<p>Could not connect to: <?php echo $current_mailbox['label']?>. Error: <?php echo imap_last_error()?></p>
<?php
} else {
$sub1 = 'SUBJECT "Query" FROM "magicbricks.com"';
$array1 = getArraySubject($stream,$sub1);
print_r($array1);
if (!count($array1)){
?>
<p>No e-mails found.</p>
<?php
} else {
$result = getDataFromHTML($array1, $domain = 0, $case = 1);
print_r($result);
}
}
// Close our imap stream.
imap_close($stream);
} // end foreach
感谢,但现在它显示了同样的错误在下一行,即find() – shweta 2014-10-10 03:28:48
@shweta'mail-data.txt'包含什么?一个html标记模板? – Ghost 2014-10-10 03:29:28
它包含邮箱的完整数据,但即使删除这3行也没有效果。 $ my_file ='mail-data.txt'; file_put_contents($ my_file,$ body); $ html = file_get_contents($ my_file,true); – shweta 2014-10-10 03:31:58