| Server IP : 80.211.21.168 / Your IP : 216.73.217.33 Web Server : Apache System : Linux alex-webdesign.it 3.10.0-1160.119.1.el7.tuxcare.els22.x86_64 #1 SMP Mon Aug 18 06:07:12 UTC 2025 x86_64 User : admin_japan ( 10003) PHP Version : 8.2.32 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/cerchijapan.it/ai4dealers.com/ |
Upload File : |
<?php
/**
* Legge le prime 2 mail (più recenti) da un account Hotmail/Outlook
* e stampa oggetto, mittente e data.
*
* Uso (da terminale):
* php leggi_prime_2_mail.php
*/
ini_set('display_errors', 1);
error_reporting(E_ALL);
// ========= CONFIGURAZIONE =========
//$hostname = '{outlook.office365.com:993/imap/ssl}INBOX';
// In alternativa, spesso funziona anche:
$hostname = '{imap-mail.outlook.com:993/imap/ssl}INBOX';
$username = 'car.selection@hotmail.com'; // <-- la tua mail Hotmail
$password = 'Adam2012'; // <-- password o app password, se la usi
// ========= CONNESSIONE IMAP =========
$inbox = imap_open($hostname, $username, $password);
if (!$inbox) {
die("Errore IMAP: " . imap_last_error() . PHP_EOL);
}
// Numero totale messaggi in INBOX
$numMessages = imap_num_msg($inbox);
if ($numMessages == 0) {
echo "Nessuna mail presente in INBOX." . PHP_EOL;
imap_close($inbox);
exit;
}
// Quante mail vogliamo leggere (max 2)
$toRead = min(2, $numMessages);
echo "Messaggi totali in INBOX: {$numMessages}" . PHP_EOL;
echo "Mostro le {$toRead} mail più recenti:" . PHP_EOL;
// Ciclo dalle più recenti (ID più alto) verso le precedenti
for ($i = $numMessages; $i > $numMessages - $toRead; $i--) {
// overview restituisce un array (anche se chiedi un solo ID)
$overviewArr = imap_fetch_overview($inbox, $i, 0);
if (!$overviewArr || !isset($overviewArr[0])) {
echo "Impossibile leggere overview per messaggio #{$i}" . PHP_EOL;
continue;
}
$overview = $overviewArr[0];
// Decodifica soggetto e mittente in UTF-8
$subject = isset($overview->subject) ? imap_utf8($overview->subject) : '(nessun oggetto)';
$from = isset($overview->from) ? imap_utf8($overview->from) : '(mittente sconosciuto)';
$date = $overview->date ?? '(data sconosciuta)';
echo "----------------------------------------" . PHP_EOL;
echo "ID IMAP: {$i}" . PHP_EOL;
echo "Da: {$from}" . PHP_EOL;
echo "Data: {$date}" . PHP_EOL;
echo "Oggetto: {$subject}" . PHP_EOL . PHP_EOL;
// Se vuoi leggere anche il corpo (testo) puoi decommentare:
/*
$body = imap_body($inbox, $i);
echo "Corpo (prime 300 lettere):" . PHP_EOL;
echo substr($body, 0, 300) . PHP_EOL . PHP_EOL;
*/
}
// Chiude connessione
imap_close($inbox);
echo "Fine lettura." . PHP_EOL;