How to get your gmail emails using php
here is the short n simple script to get your gmail inbox messages and you can store them into your database .
$imapPath = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$username = 'your-mail@gmail.com';
$password = 'your-password';
// try to connect
$inbox = imap_open($imapPath,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'UNSEEN');
$output = '';
foreach($emails as $mail) {
$headerInfo = imap_headerinfo($inbox,$mail);
$output .= $headerInfo->subject.'<br/>';
$output .= $headerInfo->toaddress.'<br/>';
$output .= $headerInfo->date.'<br/>';
$output .= $headerInfo->fromaddress.'<br/>';
$output .= $headerInfo->reply_toaddress.'<br/>';
$emailStructure = imap_fetchstructure($inbox,$mail);
if(!isset($emailStructure->parts)) {
$output .= imap_body($inbox, $mail, FT_PEEK);
} else {
//
}
echo $output;
$output = '';
}
// close the connection
imap_expunge($inbox);
imap_close($inbox);
so this script will get your all inbox unseen message on your local machine or live server.
Comments
Post a Comment