2011-03-03 13 views
6

E-posta gövdesi içeriğini alamıyorum. Gmail'den e-posta almak için kullandığınızda Posta gövdesi içeriği almak için PHP'de IMAP nasıl kullanılır?

Bu

, e-posta vücut içerik görüntülenir kodum

<?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); 
?> 

, ama benim posta sunucusunu kullanmak gelince de e-posta gövdesi içeriğini getiremezsiniz.

Bu sorunu çözmeme yardımcı olabilir misiniz?

+0

Hangi posta sunucusunu kullanıyorsunuz? – Ben

+0

Test edildi; komut dosyanız, söylediğin gibi Gmail ile iyi çalışıyor. Hatalar muhtemelen posta sunucusundan geliyor. Sağlayabileceğiniz başka detaylar var mı? – Ben

+0

Muhtemelen bir kopyası http://stackoverflow.com/questions/5170489/php5-imap-i-aint-got-no-body – dkarp

cevap

38

Ben Hata bu hat Şimdi

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

ile, çözümünü bulmuştu, ben vardı Aşağıda

text/html formatında vücut içerik almak için

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

kullanıyorum mevcut seçeneklerin ayrıntıları verilmiştir. Bu bir

()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

Teşekkürler, ben de tam olarak aynı şeyi arıyordum ... Bu yüzden de doktorlar jaja kontrol etmek de iyidir ... Sadece bir örnek kopyalayın/internet üzerinden yapıştırın ve çalışmak için bekleniyor ... –

+0

up up fetch_structure, u Kodlanmışsa mesajın kodunu çözmesi gerekir. – Andrew

0

Zeta Mail bileşeni çok daha fazla convenient fetching of mails from IMAP ve POP sağlar ve gelen e-postaları hoş ve temiz bir nesne yapısına bölebilir, böylece kolayca işleyebilirsiniz.

+1

IMAP değil POP kullanıyor. 'Imap_open' çağrısına ilk parametreyi kontrol edin. – dkarp

+0

Üzgünüm, yanlış anladım. Ancak, POP ile de çalışır: http://incubator.apache.org/zetacomponents/documentation/trunk/Mail/tutorial.html#retrieving-mail-using-pop3 – tobyS

+0

IMAP ve POP'un her ikisinin de mümkün olduğunu düşünerek yanıtımı güncelledim . – tobyS

İlgili konular