PHP Gmail IMAP Sent Items

Viewed 40

I got the sent items from gamil but how could we exclude those messages which are already fetched?? Basically, I am adding these emails to the database and want to exclude those messages which are already added to the database.

Here is a small piece of my code

$imapPath = '{imap.gmail.com:993/ssl}[Gmail]/Sent Mail';
$inbox = imap_open($imapPath, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());

$emails = imap_search($inbox, 'BODY "Ticket #" SINCE "'.date("j F Y", strtotime('yesterday')).'"');
$output = '';
$count = 0;
if (is_array($emails) || is_object($emails)) {
    $ticket_no = array();
    foreach ($emails as $mail) {
        $overview = imap_fetch_overview($inbox, $mail, 0);

        $message = imap_body($inbox, $mail, FT_PEEK);
       
        list($text,$ticketno) = explode("#",$message);
        
        $message = strstr($message, 'charset="UTF-8"');
        $message = substr($message, 16, -83);

        $message = substr($message, 0, strpos($message, "Stay well and wash those paws!"));

        $ticketno = substr($ticketno, 0, strpos($ticketno, "*"));
        $ticketno = (int)$ticketno;
    }
}
1 Answers

Got it fixed by adding msg no in the database and check on each id.

Related