[thelist] PHP parse of e-mail
Michael Pemberton
mpember at phreaker.net
Mon Sep 29 00:53:26 CDT 2003
"Ken Moore" <cor412 at hotmail.com> wrote:
> Hi all,
>
> Does anyone know of a routine to read e-mails in PHP. Especially, I want to
> automate a sign up list of people responding to e-mails. This will require
> that that PHP read the header info.
>
> If you do not know, perhaps you know where to look.
>
> TIA
>
> Ken
>
This is a simple piece of code that will use PHP's in-built IMAP/POP3 code to
read the contents of an inbox and display the details.
--------------- start code talk ---------------
$MAIL_HOST="localhost";
$MAIL_USER="test";
$MAIL_PASS="test";
// open mailbox
$inbox = @imap_open ("{". $MAIL_HOST . "/pop3:110}", $MAIL_USER, $MAIL_USER)
or die("Error: unable to open mailbox");
$total = imap_num_msg($inbox);
for($x=$total; $x>0; $x--)
{
// get header and structure
$headers = imap_header($inbox, $x);
$structure = imap_fetchstructure($inbox, $x);
htmlspecialchars($headers->fromaddress); // This is the FROM address
foreach ($headers as $key => $value) {
if (is_array($value)) $value = implode("\",\"", $value);
echo $key . " = " . htmlspecialchars($value);
}
}
// clean up
imap_close($inbox);
--------------- end code talk ---------------
Hope this is a step in the right direction.
---
Michael Pemberton
evolt at mpember.net.au
More information about the thelist
mailing list