下面我使用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; …Run Code Online (Sandbox Code Playgroud)