php script - display e-mails
Hello :)
I am looking for some kind of solution, within I could display my gmail e-mails on a website. I have found a php script, which seems to be the one I am looking for, but I simply can't get it work and almost get frustrated with it :confused:
My 2 questions:
1. If this php script is correct, where do I have to enter the e-mail, server and password to get it work for gmail?
2. If it would be an all-cach mail, is it possible to give the user a possibility to display just the e-mails, with the prefix he is looking for? (For example if the user enters "x", than he will be shown all "x@example.com" e-mails.
Thank You in advance for Your help.
Max :)
<?php
function show_mails($server, $account, $password)
{
$mailbox = imap_open("{".$server.":995/pop3}INBOX", $account, $password);
$mails = imap_fetch_overview($mailbox,"1:*", FT_UID); // This is fetching an overview of all emails
// Output as a table:
$return = '<table width="100%">
<tr>
<td><b>#</b></td>
<td><b>From</b></td>
<td><b>Date / Time</b></td>
<td><b>Subject</b></td>
</tr>';
$size = count($mails); // Number of messages
$cmsg = 0; // This is used to have a continously number
for($i=$size-1;$i>=0;$i--)
{
$cmsg++;
$value = $mails[$i];
$return .= '<tr><td>'.$cmsg.'</td><td>'.$value->from.'</td><td>'.$value->date.'</td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$value->msgno.'">'.$value->subject.'</a></td></tr>';
}
$return .= '</table>';
imap_close($mailbox);
return $return;
}
function show_mail($id, $server, $account, $password)
{
$mailbox = imap_open("{".$server.":995/pop3}INBOX", $account, $password);
$mail = imap_body($mailbox,$id, FT_UID);
// This is fetching the email..
$mail = htmlentities(stripslashes($mail));
/* stripslashes is stripping the slashes, htmlentities transforms all of the non-regular symbols to their equal html code expression. */
$return = '<pre>'.$mail.'</pre>';
imap_close($mailbox);
return $return;
}
if(isset($_GET['id']))
if(is_numeric($_GET['id']))
echo show_mail($_GET['id'], "YourServerAddress", "Account", "Password");
else
echo 'wrong parameter';
else
echo show_mails("YourServerAddress", "Account", "Password");
?>