I’m connecting to gMail using imap function. I can successfully read the INBOX mails, however, I cannot retrieve the sent mails.
[CODE]
$hostname = ‘{imap.gmail.com:}INBOX’;
$username = ‘[email protected]’;
$password = ‘mypassword’;
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to Gmail: ‘ . imap_last_error());
$emails = imap_search($inbox,’ALL’);
if($emails) {
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$header = imap_header($inbox, $email_number); // get first mails header
…. output here…..
The above works perfect for inbox. However, if I try to read the sent mail by changing the hostname with the sent mail folder (as below), it doesn’t work.
$hostname = ‘{imap.gmail.com}[Gmail]/Sent Mail
‘;
Does anyone know how to use imap functions to read sent mail in gMail?
I will need toaddress, date, subject and body fields for each sent mail.