PHP Imap Functions - anyone have experience RECEIVING email?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

PHP Imap Functions - anyone have experience RECEIVING email?

Post 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
mistermickster
Forum Newbie
Posts: 3
Joined: Wed Nov 20, 2002 9:01 am
Location: Nottingham, England

Post 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("&#123;" . "$IP:110/pop3" . "&#125;INBOX", "username", "password");
echo "<p><h2>Mail in INBOX</h2><br>";
if (imap_num_msg($mbox) > 0) &#123;
  echo "<table><th>From</th><th>Subject</th><th>Date Received</th>";
  for ($x=0; $x < imap_num_msg($mbox); $x++) &#123;
    $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>";
  &#125;
  echo "</table>";
&#125;
else &#123;
  echo "<h2><i>No Messages</i></h2>";
&#125;  
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 ("&#123;" . "$IP:110/pop3" . "&#125;", "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 :D
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post 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...?
Last edited by superwormy on Thu Nov 21, 2002 2:33 pm, edited 1 time in total.
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post 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!
mistermickster
Forum Newbie
Posts: 3
Joined: Wed Nov 20, 2002 9:01 am
Location: Nottingham, England

Post 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!! :)
Post Reply