Page 1 of 1
PHP Imap Functions - anyone have experience RECEIVING email?
Posted: Tue Nov 19, 2002 11:37 am
by superwormy
PHP Imap Functions - anyone have experience RECEIVING email?
I'm looking to just learn basic stuff how to recieve email from a POP account, all I need to know for starters is how to get a list of the emails that are there, and be able to view them. I can't find any good tutorials, anyone know of any or can provide some help?
- Keith
AIM: Superwormy
Email:
keithp@logosoftwear.com
Posted: Wed Nov 20, 2002 9:01 am
by mistermickster
I have been looking into this myself over the last couple of days and found this which I think is what you are looking for:
Call this script something like,
listmail.php
Code: Select all
<html>
<head>
<title>List INBOX Messages</title>
</head>
<body>
<?php
$IP=gethostbyname("yourpop3.address.etc");
$mbox = imap_open("{" . "$IP:110/pop3" . "}INBOX", "username", "password");
echo "<p><h2>Mail in INBOX</h2><br>";
if (imap_num_msg($mbox) > 0) {
echo "<table><th>From</th><th>Subject</th><th>Date Received</th>";
for ($x=0; $x < imap_num_msg($mbox); $x++) {
$idx=$x+1;
$info=imap_headerinfo($mbox,$idx);
$subject=$info->subject;
$from=$info->fromaddress;
$date=$info->udate;
echo "<tr><td>$from</td><td><a href='view.php?num=$idx'>$subject</a></td><td>" . date('D j/M/Y h:i',$date) . "</td></tr>";
}
echo "</table>";
}
else {
echo "<h2><i>No Messages</i></h2>";
}
imap_close($mbox);
?>
</body>
</html>
Call this script
view.php
Code: Select all
<html>
<head>
<title>View GetMailBoxes</title>
</head>
<body>
<?php
$IP=gethostbyname("yourpop3.address.etc");
$mbox = imap_open ("{" . "$IP:110/pop3" . "}", "username", "password");
$info=imap_headerinfo($mbox,$num);
$subject=$info->subject;
$from=$info->fromaddress;
$date=$info->udate;
echo "<p><h3>From : $from<br>";
echo "Received : " . date("D j/M/Y H:i",$date) . " <br>";
echo "Subject : $subject<br></h3>";
$text=imap_fetchbody($mbox,$num,"1");
echo $text . "<br>";
imap_close($mbox);
?>
</body>
</html>
Most of the functionality has been picked up from the manual at PHP.net
http://www.php.net/manual/en/ref.imap.php
Hope that helps

Posted: Thu Nov 21, 2002 2:25 pm
by superwormy
Warning: Couldn't open stream {64.72.132.17:110/pop3}INBOX in /imap_email/imap_email.php on line 5
Why do I get this...?
Posted: Thu Nov 21, 2002 2:33 pm
by superwormy
FIGURED IT OUT! THANKS!
As a note to anyone else who reads this, make sure you don't just use your ' username ' use your ENTIRE email address:
name@email.com, NOT JUST name!
Posted: Fri Nov 22, 2002 2:14 am
by mistermickster
It depends on just how your POP3 account is set up. I access mine by using a
Username with no problems at all!!
