2011-03-03 13 views
6

मैं ईमेल बॉडी सामग्री नहीं ला सकता हूं।मेल बॉडी सामग्री लाने के लिए PHP में IMAP का उपयोग कैसे करें?

यह मेरा कोड

<?php 
/* connect to server */ 
$hostname = '{myserver/pop3/novalidate-cert}INBOX'; 
$username = 'username'; 
$password = 'password'; 

/* try to connect */ 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error()); 
//echo $inbox; 
/* grab emails */ 
$emails = imap_search($inbox,'ALL'); 


/* if emails are returned, cycle through each... */ 
if($emails) { 

    /* begin output var */ 
    $output = ''; 

    /* put the newest emails on top */ 
    rsort($emails); 

    /* for every email... */ 
    foreach($emails as $email_number) { 
    //$email_number=$emails[0]; 
//print_r($emails); 
    /* get information specific to this email */ 
    $overview = imap_fetch_overview($inbox,$email_number,0); 
    $message = imap_fetchbody($inbox,$email_number,2); 

    /* output the email header information */ 
    $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 the email body */ 
    $output.= '<div class="body">'.$message.'</div>'; 
    } 

    echo $output; 
} 

/* close the connection */ 
imap_close($inbox); 
?> 

जब मैं Gmail से ईमेल लाने के लिए उपयोग करते हैं, ईमेल शरीर सामग्री प्रदर्शित किया जाता है, लेकिन एक बार मैं अपने मेल सर्वर का उपयोग, मैं ईमेल के मुख्य भाग की सामग्री को नहीं लाया जा सकता है।

क्या आप इस समस्या को ठीक करने में मेरी सहायता कर सकते हैं?

+0

आप किस मेल सर्वर का उपयोग कर रहे हैं? – Ben

+0

इसका परीक्षण किया; जैसा कि आपने कहा था, आपकी स्क्रिप्ट जीमेल के साथ ठीक काम कर रही है। त्रुटियां शायद आपके मेल सर्वर से आ रही हैं। क्या कोई अन्य विवरण है जो आप प्रदान कर सकते हैं? – Ben

+0

शायद http://stackoverflow.com/questions/5170489/php5-imap-i-aint-got-no-body – dkarp

उत्तर

38

मैं समाधान मिल गया था, त्रुटि इस लाइन

$message = imap_fetchbody($inbox,$email_number,2); 

अब साथ है, मैं

$message = imap_fetchbody($inbox,$email_number, 1.2); 

उपयोग कर रहा हूँ पाठ/HTML स्वरूप में शरीर सामग्री

नीचे मैं था प्राप्त करने के लिए उपलब्ध विकल्पों के दिए गए डेटाेल। यह कुछ

()Root Message Part (multipart/related) 
(1) The text parts of the message (multipart/alternative) 
(1.1) Plain text version (text/plain) 
(1.2) HTML version (text/html) 
(2) The background stationary (image/gif) 
+0

धन्यवाद, मैं वही चीज़ खोज रहा हूं ... यही कारण है कि दस्तावेज़ जाजा की जांच करना भी अच्छा है ... मैं सिर्फ इंटरनेट से एक उदाहरण कॉपी/पेस्ट करता हूं और काम करने की उम्मीद करता हूं ... –

+0

fetch_structure देखें, u अगर यह एन्कोड किया गया है तो संदेश को डीकोड करने की आवश्यकता है। – Andrew

0

जेता मेल घटक अधिक convenient fetching of mails from IMAP और POP की अनुमति देता है और इनकमिंग ईमेल को एक अच्छी और साफ ऑब्जेक्ट संरचना में पार्स कर सकता है ताकि आप इसे आसानी से संभाल सकें।

+1

वह पीओपी का उपयोग कर रहा है, आईएमएपी नहीं। 'Imap_open' कॉल पर पहला पैरामीटर देखें। – dkarp

+0

क्षमा करें, यह गलत हो गया। हालांकि, पीओपी के साथ भी काम करता है: http://incubator.apache.org/zetacomponents/documentation/trunk/Mail/tutorial.html#retrieving-mail-using-pop3 – tobyS

+0

मैंने यह जवाब देने के लिए अपना जवाब अपडेट किया कि IMAP और POP दोनों संभव है । – tobyS

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