I am trying to create a IMAP service on my website with help of php. It basically has few steps.
The main part that I want is that i get a list of folders of gmail account, on the click of a particular folder, the list of mails in that folder should get open and on click of any particular mail, its details should get open.
I have the list of folders, i have a list of mails, i have details of mails, but they are separate part, but i wish to combine and create one process as stated above.
The code of 3 steps is given below
Step 1 List folders: It will list all the folders of gmail. Code that i have is
$folders = imap_list($imap, "{imap.gmail.com:993/imap/ssl}", "*");
echo "<ul>";
foreach ($folders as $folder) {
$folder = str_replace("{imap.gmail.com:993/imap/ssl}", "", $folder);
$folder = str_replace("[Gmail]/", "", $folder);
echo '<li>' . $folder . '</li>';
}
echo "</ul>";
o/p of step 1
INBOX
DRAFT
SENT
TRASH
Step 2 List email (clicking on a folder mail list should get opened)
$numMessages = imap_num_msg($imap);
for ($i = $numMessages; $i > ($numMessages - 20); $i--)
{
$header = imap_header($imap, $i);
$fromInfo = $header->from[0];
$replyInfo = $header->reply_to[0];
$details = array(
"fromAddr" => (isset($fromInfo->mailbox) && isset($fromInfo->host))
? $fromInfo->mailbox . "@" . $fromInfo->host : "",
"fromName" => (isset($fromInfo->personal))
? $fromInfo->personal : "",
"replyAddr" => (isset($replyInfo->mailbox) && isset($replyInfo->host))
? $replyInfo->mailbox . "@" . $replyInfo->host : "",
"replyName" => (isset($replyTo->personal))
? $replyto->personal : "",
"subject" => (isset($header->subject))
? $header->subject : "",
"udate" => (isset($header->udate))
? $header->udate : ""
);
$uid = imap_uid($imap, $i);
$datee= gmdate("F j, Y, g:i a", $details["udate"] );
echo "<ul>";
echo "<li><strong>From:</strong>" . $details["fromName"];
echo " " . $details["fromAddr"] . "</li>";
echo "<li><strong>Subject:</strong> " . $details["subject"] . "</li>";
echo "<li><strong>DATE:</strong> " . $datee . "</li>";
}
o/p of step 2 (clicking on a particular mail content of that mail should get opened)
From:ABC
Subject: TOPIC
DATE: September 2, 2015, 9:00 am
Step 3 View messages
$message_count = imap_num_msg($imap);
for ($i = 1; $i <= $message_count; ++$i) {
$header = imap_header($imap, $i);
$body = trim(substr(imap_body($imap, $i), 0, 100));
$prettydate = date("jS F Y", $header->udate);
if (isset($header->from[0]->personal)) {
$personal = $header->from[0]->personal;
} else {
$personal = $header->from[0]->mailbox;
}
$email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
echo "On $prettydate, $email said \"$body\".\n";
}
Can anyone please tel how i can achieve the above requirement