init
This commit is contained in:
65
email.php
Normal file
65
email.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
function loadGmailMails($from = 0, $to = 10) {
|
||||
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
|
||||
$username = 'outtervision';
|
||||
$password = 'rudemodz@#$12345';
|
||||
|
||||
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: '.imap_last_error());
|
||||
$e = imap_search($inbox, 'ALL');
|
||||
$emails = array();
|
||||
if ($e) {
|
||||
rsort($e); // najnowsze na gorze
|
||||
|
||||
if ($to == 0) {
|
||||
$to = sizeof($e);
|
||||
}
|
||||
|
||||
for ($i = $from; $i < $to; $i++) {
|
||||
$overview = imap_fetch_overview($inbox, $e[$i], 0); // pobieramy naglowek
|
||||
$message = imap_fetchbody($inbox, $e[$i], 1); // pobieramy tresc
|
||||
|
||||
preg_match('/(?P<name>[a-zA-Z ]+)<(?P<address>.+)>/', $overview[0]->from, $match); // wyciagamy nadawce oraz jego email
|
||||
$name = isset($match['name']) ? trim($match['name']) : '';
|
||||
$address = isset($match['address']) ? trim($match['address']) : '';
|
||||
|
||||
// tworzymy tablice z danymi konkretnego emaila
|
||||
$emails[] = array(
|
||||
'read' => $overview[0]->seen,
|
||||
'subject' => $overview[0]->subject,
|
||||
'from' => array(
|
||||
'name' => $name,
|
||||
'address' => $address
|
||||
),
|
||||
'date' => $overview[0]->date,
|
||||
'message' => $message
|
||||
);
|
||||
}
|
||||
}
|
||||
imap_close($inbox);
|
||||
|
||||
return $emails;
|
||||
}
|
||||
|
||||
$r=loadGmailMails();
|
||||
echo '<pre>';
|
||||
print_r($r);
|
||||
echo '</pre>';
|
||||
|
||||
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
|
||||
$username = 'outtervision';
|
||||
$password = 'rudemodz@#$12345';
|
||||
|
||||
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: '.
|
||||
$list = imap_getmailboxes($inbox, "{imap.gmail.com}", "*");
|
||||
if (is_array($list)) {
|
||||
foreach ($list as $key => $val) {
|
||||
echo "($key) ";
|
||||
echo imap_utf7_decode($val->name) . ",";
|
||||
echo "'" . $val->delimiter . "',";
|
||||
echo $val->attributes . "<br />\n";
|
||||
}
|
||||
} else {
|
||||
echo "imap_getmailboxes failed: " . imap_last_error() . "\n";
|
||||
}
|
||||
|
||||
imap_close($mbox);
|
||||
Reference in New Issue
Block a user