1) { rsort($messages); $count = count($messages); echo "You have $count new unread mails"; echo "To hear the body of a mail, press 1 after the subject is read, press 0 to exit anytime"; get_subject($messages,$count,$subject,$header,$mail); for($i=0;$i<$count;$i++){ $voicetype = ($i&1)?"female":"male"; setvoiceoption("voicetype", $voicetype); $op = prompt($subject[$i], 1, 1, "dtmf:1"); if($op == "1") { read_mail($messages[$i], $mail); echo "Returning to subject menu"; } elseif($op == "0") { break; } } } else { echo "You have no new mails"; } imap_close($mail); echo "Thank you for trying Voice PHP Demo"; //Get the subject of the mail .. function get_subject($messages,$count,&$subject,&$header,$mail){ for($i=0;$i<$count;$i++) { //Get IMAP header info for mail $header = imap_headerinfo($mail, $messages[$i]); $subject[$i] = "Mail from " . $header->from[0]->personal . " with subject " . $header->subject; } } //Read a mail body.. function read_mail($num,$mail) { // Get the message body $st = imap_fetchstructure($mail, $num); if (!empty($st->parts)) { for ($i = 0, $j = count($st->parts); $i < $j; $i++) { $part = $st->parts[$i]; if ($part->subtype == 'PLAIN') { $body = imap_fetchbody($mail, $num, $i+1); } } } else { $body = imap_body($mail, $num); } echo $body; } ?>