2012-10-11 18 views
8

मैं एक ईमेल निकाय लाने की कोशिश कर रहा हूं और इसके आधार पर सीखने वाले को उत्तर भेज रहा हूं। लेकिन मुझे अपना कोड निष्पादित करते समय Notice: Undefined property: stdClass::$subject त्रुटि मिल रही है। मैं वास्तव में नहीं जानता कि क्या करना है। मैं नीचे कोड पोस्ट कर रहा हूँ।नोटिस: अपरिभाषित संपत्ति: stdClass: त्रुटि

<?php 

$server = '{imap.aaa.com:993/imap/ssl}INBOX'; 
$username = '[email protected]'; 
$password = 'aaaaaa'; 
require_once '../swift/lib/swift_required.php'; 

$connection = imap_open($server,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 

$result = imap_search($connection,'ALL'); 
if($result) { 


    $output = ''; 


    rsort($result); 


    foreach($result as $email_number) { 

    $overview = imap_fetch_overview($connection,$email_number,0); 
    $message = imap_fetchbody($connection,$email_number,2); 

    $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; 
    $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; 
    $output.= '<span class="from">'.$overview[0]->from.'</span>'; 
    $output.= '<span class="date">on '.$overview[0]->date.'</span>'; 
    $output.= '</div>'; 

    $output.= '<div class="body">'.$message.'</div>'; 

    if ($message == signup) 

    { 

$transport = Swift_MailTransport::newInstance(); 
$mailer = Swift_Mailer::newInstance($transport); 

$message1 = Swift_Message::newInstance('new message') 
    ->setFrom(array('[email protected]' => 'name')) 
    ->setTo(array('[email protected]')) 
    ->setBody($message); 


    $mail = $mailer->send($message1); 
    } 

    } 
} 

else 
{ 
    echo "false return"; 
} 
?> 
+0

त्रुटि संदेश लगता है काफी स्पष्ट है, '$ सिंहावलोकन [0] -> विषय 'परिभाषित नहीं किया गया है :) तो 'var_dump ($ सिंहावलोकन [0])' कार्रवाई का अगला कोर्स होगा। –

+0

लेकिन मुझे आश्चर्य है कि केवल $ ओवरव्यू [0] -> विषय को परिभाषित क्यों करें। जब और तारीख से अधिक समान डेटा होते हैं? – faz

उत्तर

17

imap_fetch_overview के लिए दस्तावेज़ से:

 
Returns an array of objects describing one message header 
each. The object will only define a property if it exists. 

तो जाँच संपत्ति पहले सेट है, तो:

if (isset($overview[0]->subject)) 
{ 
    $output.= '<span class="subject">'.$overview[0]->subject.'</span> '; 
} 
+0

क्रमबद्ध। धन्यवाद। इस विशेष मेल में कोई विषय नहीं था। – faz

+0

मेरा दिन बचाओ, धन्यवाद आदमी! –

संबंधित मुद्दे