以下では、PHP の imap ライブラリを使用してメールをループしています。動作しますが、メッセージから添付ファイルを保存することに固執しています。
<?php
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'someemail@somedomain.com';
$password = 'somepassword';
/* try to connect */
$imap_connection = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($imap_connection,'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) {
$structure = imap_fetchstructure($imap_connection,$email_number);
if(isset($structure->parts) && count($structure->parts)){
for($i = 0; $i < count($structure->parts); $i++){
if(!empty($structure->parts[$i]->bytes)){
if(!empty($ifdparameters)){
echo "File: ----".$structure->parts[$i]->dparameters[0]->value;
// returns: testMeOut.jpg
}
}
} //eof $i loop
} //eof $structure->parts
} // eof foreach $emails
} // eof if($emails)
?>
サーバー上のディレクトリに添付ファイルを保存する方法を理解しようとしています。$structure->parts[$i]->dparameters[0]->value; 添付ファイルの名前を返しています。
imap_fetchbody() で何かする必要があると確信していますが、オンラインのチュートリアルと php のサイトを読んで混乱しています。
$message から添付ファイルを保存する方法について、私の最後のいくつかの手順が抜けているのを誰かが見ることができますか?