Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. /* Fabyo Guimaraes
  4. data = 06/02/2005*/
  5.  
  6. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  7. $username = 'davidwalshblog@gmail.com';
  8. $password = 'davidwalsh';
  9.  
  10. @ini_set('display_errors', '0');
  11. $mbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
  12.  
  13. $erro[] = imap_last_error();
  14. // testo se tem email no servidor
  15. if ($erro[0] == "Mailbox is empty") {
  16.     echo "não tem nenhuma mensagem";
  17.     exit;
  18. }
  19. // verifico se esta certo o usuario e senha
  20. elseif ($erro[0] == "POP3 connection broken in response") {
  21.     echo "Usuario ou a senha estao errados";
  22.     exit;
  23. }
  24. // testo se o servidor esta certo
  25. elseif ($erro[0] == "Host not found (#11004): pop3.$servidor") {
  26.     echo "O servidor $servidor esta errado";
  27.     exit;
  28. }
  29. // se a $erro estiver vazia ele continua
  30. if ($erro[0] == "") {
  31.     $numero_mensagens = imap_num_msg($mbox);
  32.     $numero_mens_nao_lidas = imap_num_recent($mbox);
  33.  
  34.     if ($numero_mensagens == 1) {
  35.         echo "você tem $numero_mensagens mensagem";
  36.     } else {
  37.         echo "você tem $numero_mensagens mensagens";
  38.     }
  39.  
  40.     echo "<br><br>";
  41.  
  42.     for($i = 1;$i <= imap_num_msg($mbox);$i++) {
  43.        
  44.   $headers            = imap_header($mbox, $i);
  45.         $assunto            = $headers->subject;
  46.         $message_id         = $headers->message_id;
  47.         $toaddress          = $headers->toaddress;
  48.         $to                 = $headers->to;
  49.         $remetente          = $to[0]->personal;
  50.         $email_remetente    = $to[0]->mailbox;
  51.         $servidor_remetente = $to[0]->host;
  52.         $data               = $headers->date;
  53.         $data               = strtotime($data);
  54.         $data               = date("d/m/Y H:i:s", $data);
  55.  
  56.         echo "Assunto = $assunto - Remetente = $email_remetente@$servidor_remetente Data = $data <a href=\"imap.php?id=$i\">Ler Mensagem</a><br>";
  57.     }
  58.  
  59.     echo "<br>";
  60.     if (isset($_GET["id"])) {
  61.         $id = $_GET["id"];
  62.  
  63.         $mensagem = imap_fetchbody($mbox, $id, 1);
  64.         echo nl2br(quoted_printable_decode($mensagem));
  65.     }
  66.  
  67.     imap_close($mbox);
  68. }
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement