Incoming email read with php

Posted: January 19, 2011 in PHP5
Tags:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>

<style>
div.toggler { border:1px solid #ccc; background:url(gmail2.jpg) 10px 12px #eee no-repeat; cursor:pointer; padding:10px 32px; }
div.toggler .subject { font-weight:bold; }
div.read { color:#666; }
div.toggler .from, div.toggler .date { font-style:italic; font-size:11px; }
div.body { padding:10px 20px; }
</style>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script&gt;
<script type=”text/javascript”>
$(document).ready(function(){
$(“.toggler “).click(function(){
$(“.body”).toggle();
});
});
</script>

</head>

<body>

<?php
ini_set(“max_execution_time”,360);

/* connect to server */
$hostname = ‘{domain.com:143/notls}INBOX’;
$username = ‘amit@domain.com’;
$password = ‘amitmondal’;

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to domain:’ . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,’ALL’);

/* if emails are returned, cycle through each… */
if($emails) {

$output = ”;

/* put the newest emails on top */
rsort($emails);

echo “Number of email:”.imap_num_msg($inbox);

/* for every email… */
foreach($emails as $email_number) {

$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,1);

$output.= ‘<div class=”toggler ‘.($overview[0]->seen ? ‘read’ : ‘unread’).'”>’;
$output.= ‘<span class=”subject”>’.$overview[0]->subject.'</span> ‘;
$output.= ‘<span class=”from”>’.$overview[0]->from.'</span>’;
$output.= ‘<span class=”date”>on ‘.$overview[0]->date.'</span>’;
$output.= ‘</div>’;

$output.= ‘<div class=”body”>’.$message.'</div>’;
} //end of for loop
echo $output;
} //end of if statement

/* close the connection */
imap_close($inbox);

?>

</body>
</html>

Advertisements
Comments
  1. Ehtel Hamper says:

    Excellent piece. I was checking constantly this blog and I am quite impressed! Very useful information specifically the first part. I care for such information much. I was looking for this particular info for a very long time. Thank you and best of luck.

  2. Excellent post. I was checking continuously this blog and I’m impressed! Extremely helpful information particularly the first part. I care for such information a lot. I was seeking this certain info for a very long time. Thank you and good luck.

  3. Edwin Bonde says:

    Excellent blog. I was checking constantly this blog and I’m impressed! Extremely useful information particularly the first part. I care for such info a lot. I was looking for this particular information for a long time. Thank you and best of luck.

  4. Vinita Noya says:

    Excellent piece. I was checking constantly this blog and I’m impressed! Extremely helpful info specially the first part. I care for such information a lot. I was looking for this particular information for a very long time. Thank you and best of luck.

  5. Josh Purcell says:

    Parse error: syntax error, unexpected ‘{‘ in /home/a2376620/public_html/Mail.php on line 30

  6. Pareen says:

    Parse error: syntax error, unexpected ‘{‘ in /home/a2376620/public_html/Mail.php on line 30

    Same here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s