Skip to content

Instantly share code, notes, and snippets.

@dnovais
Last active August 29, 2015 14:10
Show Gist options
  • Save dnovais/dbfb4a15770a845795a7 to your computer and use it in GitHub Desktop.
Save dnovais/dbfb4a15770a845795a7 to your computer and use it in GitHub Desktop.
Exemplo de como recuperar todas as mensagens do Gmail com PHP e IMAP.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Um Exemplo</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>
<body>
<table class="table table-bordered">
<th>Remetente</th>
<th>Data</th>
<th>Assunto</th>
<th>Corpo</th>
<?php
ini_set('display_errors', 1);
// Dados para acesso à conta de e-mail no servidor.
$server = "{pop.ppt.net.br:110/pop3/novalidate-cert}INBOX";
$email_address = "[email protected]";
$pasword = "********************************";
$inbox = imap_open($server, $email_address, $pasword) or die("Não foi possível concluir a conexão!");
$emails_list = imap_search($inbox, "ALL");
if($emails_list){
// Ordena os e-mails
rsort($emails_list);
// Itera na lista de e-mails
foreach ($emails_list as $email) {
$overview = imap_fetch_overview($inbox, $email, 0);
$message = imap_fetchbody($inbox, $email, 2);
?>
<tr>
<td><?= $overview[0]->from ?></td>
<td><?= $overview[0]->date ?></td>
<td><?= $overview[0]->subject ?></td>
<td><?= $message ?></td>
</tr>
</table>
<?php
}
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment