Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CavemanUK

macrumors 6502
Original poster
Jun 29, 2006
456
69
Rhyl, North Wales
hi,

i have made a private site that shows me my new email. I would like to make each entry a link back to the googlemail site and direct straight to that message (a lot like mail notifiers do). does anyone know how to do this.. my code is below..

Code:
<?php
 						// gmail email checker
       			/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'gmailaccount@gmail.com';
$password = 'password';


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

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

/* if emails are returned, cycle through each... */
if($emails) {
	
	/* begin output var */
	$output = '';
	
	/* put the newest emails on top */
	rsort($emails);
	echo "<ul id='gmailbox'><h3>Gmail</h3>";
	/* for every email... */
	foreach($emails as $email_number) {
		
		/* get information specific to this email */
		$overview = imap_fetch_overview($inbox,$email_number,0);
		/* $message = imap_fetchbody($inbox,$email_number,2); */
		
		/* output the email header information */
		$output.= '<li><span class="gmailfrom">'.substr($overview[0]->from,0,25).'</span>';
		$output.= '<span class="gmailsubject">'.ereg_replace("[^A-Za-z0-9 _]", "", substr($overview[0]->subject,0,35)).'</span> ';
		$output.= '</li>';
		
	}
	
	echo $output;
	echo "</ul>";
} 

/* close the connection */
imap_close($inbox);
				
 					
 ?>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.