Вот мой PHP-код для захвата электронных писем Gmail и их отображения на веб-странице:
<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'username@gmail.com';
$password = 'password';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* 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) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox, $email_number, 0);
$message = imap_fetchbody($inbox, $email_number, 1);
$DateFormatted = str_replace("-0500", "", $overview[0] -> date);
/* output the email header information */
$output .= $overview[0] -> subject ;
$output .= $DateFormatted ;
//$bodyFormatted = preg_replace("/This e-mail(.*)/","",$message);
//$bodyFormatted = preg_replace("/Ce courriel(.*)/","",$bodyFormatted);
/* output the email body */
$output .= $message;
}
echo $output;
}
/* close the connection */
imap_close($inbox);
?>
Проблема, с которой я сталкиваюсь, заключается в том, что я получаю странные заголовки, выпадающие из тела сообщения, и не вижузнаю, почему.Я не могу использовать str replace или Regex, потому что числовая часть заголовков генерируется каждый раз по-разному, поэтому мне действительно нужен надежный способ сделать это.У меня нет идей, и мне нужна помощь.Также получаются случайные знаки "="
Вывод:
SiteA Connectivity Issues (resolved)Tue, 6 Dec 2011 13:59:59 **------_=_NextPart_001_01CCB449.406E7C50 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable =20** Please be advised www.siteA.com is no longer experiencing issues. The site is up and fully operational once again. =20 IMPACT: www.siteA.com was experiencing connectivity issues.=20 =20 UPDATE: Connectivity issues have been resolved. Root cause analysis and reporting will be performed tomorrow during business hours. **=20 ------_=_NextPart_001_01CCB449.406E7C50 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable**
Please be advised www.siteA.com is no longer = experiencing issues. The site is up and fully operational once = again.
IMPACT:
www.siteA.com was experiencing connectivity issues.
UPDATE:
Connectivity issues have been = resolved. Root cause analysis and reporting will be performed tomorrow during = business hours.
**------_=_NextPart_001_01CCB449.406E7C50--**