Parsing Mail with PHP - Derick Rethans
-
There are lots of implementations on sending mails for PHP, but mail parsers have generally been hard to come by.Here’s a new Pear Package which allows you to easily parse mails in PHP. Check below for a script which uses package to parse mails.
< ?php
require_once "ezc/Base/base.php";function __autoload( $className ){
ezcBase::autoload( $className );
}$pop3 = new ezcMailPop3Transport( "pop3.example.com" );
$pop3->authenticate( “user”, “password” );
$set = $pop3->fetchAll();
$parser = new ezcMailParser();
$mails = $parser->parseMail( $set );foreach ( $mails as $mail ) {
echo “From: {$mail->from->email}\n”;
echo “To: “;
foreach ( $mail->to as $to ) {
echo “{$to->name} ({$to->email}) “;
}
echo “\n”;
echo “Subject: {$mail->subject}\n”;
switch ( get_class( $mail->body ) ) {
case ‘ezcMailText’: echo “Text part, “. “type={$mail->body->subType}\n–\n”;
echo $mail->body->text;
echo “\n–\n”;
break;
case ‘ezcMailMultipartMixed’: echo “Multipart mail\n”;
break;
}echo “\n”;
}
?>
Link: Parsing Mail with PHP - Derick Rethans























