get email data from Gmail on the base of UID

firebase get user data by uid
firebase get user by uid
gmail api get all emails
google analytics email tracking example
gmail api get unread messages
firebase get current user email
gmail api get message subject
gmail api get messages

I want to fetch emails detail from my gmail account and save into Mysql Table. I wan to Fetch emails on the base of UID. But I am not getting the required results. Can anyone tell me how I can fetch Email, Subject, Body of the email when a new email arrives on my gmail account. Here is my code :

/* connect to server */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myemail';
$password = 'mypassword';

/* try to connect */
$inbox = imap_open($hostname,$username,$password,OP_READONLY) or die('Cannot connect to Tiriyo: ' . imap_last_error());
//echo $inbox;
/* grab emails */
//$emails = imap_search($inbox,'ALL');
$latest_uid = 16; // Last UID inserted in my table 

$emails   = imap_search($inbox, 'ALL', SE_UID);
print_r($emails);
/* if emails are returned, cycle through each... */
if($emails) {

  /* begin output var */
  $output = '';

  /* put the newest emails on top */
  rsort($emails);

  /* for every email... */
  foreach($emails as $email_number) {
    //$email_number=$emails[0];
//print_r($emails);
    /* get information specific to this email */
    $message = imap_fetchbody($inbox,$email_number, 1);
    //echo $message;
    $overview = imap_fetch_overview($inbox,"1:{$email_number}");
   // $message = imap_fetchbody($inbox,$email_number,2);

    /* output the email header information */
   // $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
    $output.= '<span class="subject">'.$overview->subject.'</span> ';
    $output.= '<span class="from">'.$overview->from.'</span>';


     $output.= '<span class="from">'.$overview->uid.'</span>';

    $output.= '</div>';

    /* output the email body */
    $output.= '<div class="body">'.$message.'</div>';
  }

  echo $output;
}

/* close the connection */
imap_close($inbox);

I am getting error :

Notice: Trying to get property of non-object in C:\xampp\htdocs\imap\custom\index2.php on line 37

Notice: Trying to get property of non-object in C:\xampp\htdocs\imap\custom\index2.php on line 38

Notice: Trying to get property of non-object in C:\xampp\htdocs\imap\custom\index2.php on line 41

this is line 37:

$output.= '<span class="subject">'.$overview->subject.'</span> ';

Try This code :

$mbox = imap_open("Hostname", "username", "password")
     or die("can't connect: " . imap_last_error());

$MC = imap_check($mbox);

// Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
foreach ($result as $overview) {
    echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from}
    {$overview->subject}\n";
}
imap_close($mbox);

Let me know result.

Email Tracking, Caution: You may not upload any data that allows Google to personally We recommend placing the image at the bottom of the email, so it does not delay email you can use the Client ID from analytics.js using the get method. User ID (​&uid) you can't use the measurement protocol to track Gmail users. If you are sending as a Gmail user through smtp.gmail.com, then try these steps. If you have two-step verification enabled on the account, you will need to use an application specific password (created in the Gmail account) in the database settings: Signing in using application-specific passwords

Try to change the '' for ""

like this: $output.= "<span class='subject'>".$overview->subject."</span> ";

More info

Users.messages: get | Gmail API, raw ": Returns the full email message data with body content in the raw field as a base64url encoded string; the payload field is not used. The Less Secure App Access feature of the Gmail should be enabled. The 2 – Step verification of the Gmail account must be disabled. Step-by-Step Procedure to Search in Gmail.com User Account 1. Enable IMAP and POP in Gmail: – Login to your Gmail Account and click on the Gear button present at the right section and click on “Settings”

i have one link for you it helps you

http://php.net/manual/en/function.imap-search.php

there is all type of conditions and filters link available

ALL - return all messages matching the rest of the criteria
ANSWERED - match messages with the \\ANSWERED flag set
BCC "string" - match messages with "string" in the Bcc: field
BEFORE "date" - match messages with Date: before "date"
BODY "string" - match messages with "string" in the body of the message
CC "string" - match messages with "string" in the Cc: field
DELETED - match deleted messages
FLAGGED - match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
FROM "string" - match messages with "string" in the From: field
KEYWORD "string" - match messages with "string" as a keyword
NEW - match new messages
OLD - match old messages
ON "date" - match messages with Date: matching "date"
RECENT - match messages with the \\RECENT flag set
SEEN - match messages that have been read (the \\SEEN flag is set)
SINCE "date" - match messages with Date: after "date"
SUBJECT "string" - match messages with "string" in the Subject:
TEXT "string" - match messages with text "string"
TO "string" - match messages with "string" in the To:
UNANSWERED - match messages that have not been answered
UNDELETED - match messages that are not deleted
UNFLAGGED - match messages that are not flagged
UNKEYWORD "string" - match messages that do not have the keyword "string"
UNSEEN - match messages which have not been read yet
$s_Date = "20 January 2018";
$b_Date = "10 December 2018"; 
$emails = imap_search($inbox,'SINCE "'.$s_Date.'" BEFORE"'.$b_Date.'"' );

now you can do your desire you need to some changes

like below :-

$emails = imap_search($inbox, 'NEW');

Manage Users in Firebase, String email = user.getEmail(); Uri photoUrl = user.getPhotoUrl(); // Check if user's email is verified boolean emailVerified = user.isEmailVerified(); // The user's ID  Gmail IMAP to database sync. How to get UID of Email Appended to IMAP Mailbox? Unable to read Gmail emails using IMAP (android email library) Chilkat reports wrong number of emails in GMail POP3 mailbox? imap copy - what uid does new message have? Login to GMail using OAuth2 authentication. Copying an IMAP message: How to get new UID?

Set up User-ID - Analytics Help, Get Started · Structure Data · Save Data · Retrieve Data. REST var name, email​, photoUrl, uid, emailVerified; if (user != null) { uid = user.uid; // The user's ID, unique to the Firebase project. You can update a user's basic profile information—the user's display name and profile photo URL—with the updateProfile method. This works if I input an uid directly but I would like to have my input be an email and get an uid out from it, or if there are other solutions please suggest. This is how the database structure looks like: Thanks for the help in advance.

Remember your user, To set up the User-ID feature, you must first enable it in your Analytics account You also have to create a User-ID view to see the data in your Analytics reports. The answer is very known and obvious that Google uses a BigTable and they've released a few papers describing it out into the real world. Bigtable is a distributed storage system for managing structured data that is designed to scale to a very lar

accounts.getAccountInfo REST - Gigya Documentation, Auto-fill forms with the user's email address. Retrieve an ID that is tied to a user, not the device. Determine if AccountManager is for you. If this happens then you will of course lose all of the associations between emails and extra data (notes or contacts). You can rely on this: a UID will never suddenly refer to a different message. Either it will remain valid and refer to the same message it always referred to, or else it will become invalid.

Comments
  • which is line 37?
  • see the edit question
  • did you try this $emails = imap_search($inbox, 'NEW '); i hope it helps you better. thanks.
  • it is fetching all the emails
  • do you have a need to a specific user?
  • No, I want to fetch only new emails
  • Try to change the '' for "" Why should they?