(PHPでの初めてのプログラミング。助けがありました。もう少し必要です。)
ゴール:
Gmailアカウントの特定のメールアドレスからlastContactDateを取得します。「[Person]に最後に連絡したのはいつですか」という質問に答えたいと思っています。
私がこれまでにしたこと:
- imapを使用してGmailに接続(受信トレイのみ)
- 日付と時刻を取得しました
- 人の名前とタイムスタンプを印刷しました。
私ができないこと:
- アーカイブされたlastContactDateのメールを精査します(私は受信トレイ= 0の人です)
ノート:
- コードは大まかなものですが、機能的です。PHPは実際には別のページに分割する必要がありますが、これは最初の試みです。助けてくれてありがとう!
- 愛するプログラミング、ところで。過去2日間に@edw519のダンスを2回以上行いました。
リサーチ:
- imap_openとimap_searchのパラメータをいじることがおそらく私の最善の策だと思いますが、確かではありません。
- これらの2つのページを頻繁に使用しています。
- http://php.net/manual/en/function.imap-open.php
- http://php.net/manual/en/function.imap-search.php
これまでに使用されたコード:
/* 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.= '<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="from">'.$overview[0]->from.'</span> ';
$output.= '<span class="date">on '.$overview[0]->date.'</span> <br /><br />';
mysql_query("UPDATE users SET lastContactDate = '".$overview[0]->date."' WHERE email = '".$findemail."'") or die(mysql_error());
/* output the email body */
/* $output.= '<div class="body">'.$message.'</div>'; */
}
echo $output;
}
}
/* close the connection */
imap_close($conn);
?>