( Первый раз программирование на PHP. Была некоторая помощь. Нужно еще немного. )
Цель:
Вытащить lastContactDate с указанного адреса электронной почты из моей учетной записи Gmail. Надеюсь ответить на вопрос: «Когда в последний раз я обращался к [Человеку]»
Что я сделал на данный момент:
Что я не могу сделать:
Примечания:
Исследование:
Используемый код:
/* connect to gmail */
$gmailhostname = '{imap.gmail.com:993/imap/ssl}';
$gmailusername = "___@gmail.com";
$gmailpassword = "___";
/* try to connect */
$conn = imap_open($gmailhostname,$gmailusername,$gmailpassword) or die('Cannot connect to Gmail: ' . imap_last_error());
$query = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_array($query))
{
$findemail = $row["email"];
/* grab emails */
$emails = imap_search($conn,'FROM "'.$findemail.'"');
/* if emails are returned, cycle through each... */
if ($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for 5 emails... */
$emails = array_slice($emails,0,1);
foreach ($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($conn,$email_number,0);
$message = imap_fetchbody($conn,$email_number,2);
/* output the email header information */
/*
$output.= '';
$output.= ''.$overview[0]->subject.' ';
$output.= ''.$overview[0]->from.'';
*/
$output.= ''.$overview[0]->from.' ';
$output.= 'on '.$overview[0]->date.'
';
mysql_query("UPDATE users SET lastContactDate = '".$overview[0]->date."' WHERE email = '".$findemail."'") or die(mysql_error());
/* output the email body */
/* $output.= ''.$message.''; */
}
echo $output;
}
}
/* close the connection */
imap_close($conn);
?>
23
задан Yes Barry 17 November 2011 в 22:20
поделиться