Fetch unread gmail emails using PHP

By | January 27, 2017

You can easily Fetch unread gmail emails using PHP. You can get unread Emails count by gmail feeds.Here is a example how to get unread email count in your gmail account.

/*

If you want to use this function add your account details  in varibales.

*/
 
function get_gmail($username , $password)
{
    $url = "https://mail.google.com/mail/feed/atom";
     
    $c = curl_init();
     
    $options = array(
        CURLOPT_HTTPAUTH => CURLAUTH_BASIC ,
        CURLOPT_USERPWD => "$username:$password" ,
        CURLOPT_SSLVERSION => 3 ,
        CURLOPT_SSL_VERIFYPEER => FALSE ,
        CURLOPT_SSL_VERIFYHOST => 2 ,
        CURLOPT_RETURNTRANSFER => true ,
        CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" ,
        CURLOPT_URL => $url
    );
     
    curl_setopt_array($c, $options);
    $output = curl_exec($c);
     
    return $output;
}
 
$gmail_username = 'username';
$gmail_password = 'password';
 
echo get_gmail( $gmail_username , $gmail_password );

if you have any questions in my mind. Freely ask on comments.

Category: PHP

Leave a Reply

Your email address will not be published. Required fields are marked *