Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. public function index()
  2. {
  3. /* connect to gmail */
  4. $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
  5. $username = 'febry.rizky@cbncloud.co.id';
  6. $password = '-------------';
  7.  
  8. $inbox = imap_open($hostname, $username, $password) or die('Cannot connect: ' . imap_last_error());
  9.  
  10. $emails = imap_search($inbox, 'ALL');
  11.  
  12. if ($emails) {
  13. $output = '';
  14. $mails = array();
  15.  
  16. rsort($emails);
  17.  
  18. foreach ($emails as $email_number) {
  19. $header = imap_headerinfo($inbox, $email_number);
  20. $message = quoted_printable_decode (imap_fetchbody($inbox, $email_number, 1));
  21.  
  22. $from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
  23. $toaddress = $header->toaddress;
  24. if(imap_search($inbox, 'ALL')){
  25. /*Store from and message body to database*/
  26. if(($from) == 'febririzki46@yahoo.com')
  27. {
  28. DB::table('email')->insert(['from'=>$from, 'body'=>$message]);
  29. }
  30. else
  31. {
  32. die();
  33. }
  34.  
  35. //return view('emails.display');
  36. }
  37. else{
  38. $data = Email::all();
  39. //return view('emails.display',compact('data'));
  40.  
  41. }
  42. }
  43. }
  44. imap_close($inbox);
  45. }
  46.  
  47. public function showMail($id){
  48.  
  49. // get the id
  50. $message = Email::findOrFail($id);
  51. $m = $message->body;
  52. // show the view and pass the nerd to it
  53. return view('emails.showmail',compact('m'));
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement