Email Reading Library (Source Code)
![]()
With the support of component ezc , You can read your email via pop3 protocol.
The email and password used here are only for temporary purpose. Try this code:
Click more for source code:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
require_once("ezc/Base/base.php");
function __autoload( $className )
{
ezcBase::autoload( $className );
}
$pop3 = new ezcMailPop3Transport( "torque.co.in" );
$pop3->authenticate( temp@temp.com, "password" );
$set = $pop3->fetchAll(); // if you put "true" inside this function, all the mail will be deleted after retrieving. eg: fetchAll(true)
$parser = new ezcMailParser();
$mails = $parser->parseMail( $set );
$mail = end($mails);
echo formatMail($mail);
function formatMail( $mail )
{
$t = '';
$t .= "From: ". formatAddress( $mail->from ). "\n";
$t .= "To: ". formatAddresses( $mail->to ). "\n";
$t .= "Cc: ". formatAddresses( $mail->cc ). "\n";
$t .= "Bcc: ". formatAddresses( $mail->bcc ). "\n";
$t .= 'Date: '. date( DATE_RFC822, $mail->timestamp ). "\n";
$t .= 'Subject: '. $mail->subject . "\n";
$t .= "MessageId: ". $mail->messageId . "\n";
$t .= "\n";
$t .= formatMailPart( $mail->body );
return $t;
}
function formatMailPart( $part )
{
if ( $part instanceof ezcMail )
return formatMail( $part );
if ( $part instanceof ezcMailText )
return formatMailText( $part );
if ( $part instanceof ezcMailFile )
return formatMailFile( $part );
if ( $part instanceof ezcMailRfc822Digest )
return formatMailRfc822Digest( $part );
if ( $part instanceof ezcMailMultiPart )
return formatMailMultipart( $part );
die( "No clue about the ". get_class( $part ) . "\n" );
}
function formatMailMultipart( $part )
{
if ( $part instanceof ezcMailMultiPartAlternative )
return formatMailMultipartAlternative( $part );
if ( $part instanceof ezcMailMultiPartDigest )
return formatMailMultipartDigest( $part );
if ( $part instanceof ezcMailMultiPartRelated )
return formatMailMultipartRelated( $part );
if ( $part instanceof ezcMailMultiPartMixed )
return formatMailMultipartMixed( $part );
die( "No clue about the ". get_class( $part ) . "\n" );
}
function formatMailMultipartMixed( $part )
{
$t = '';
foreach ( $part->getParts() as $key => $alternativePart )
{
$t .= "-MIXED-$key------------------------------------------------------------------\n";
$t .= formatMailPart( $alternativePart );
}
$t .= "-MIXED END----------------------------------------------------------\n";
return $t;
}
function formatMailMultipartRelated( $part )
{
$t = '';
$t .= "-RELATED MAIN PART-----------------------------------------------------------\n";
$t .= formatMailPart( $part->getMainPart() );
foreach ( $part->getRelatedParts() as $key => $alternativePart )
{
$t .= "-RELATED PART $key-----------------------------------------------------\n";
$t .= formatMailPart( $alternativePart );
}
$t .= "-RELATED END--------------------------------------------------------\n";
return $t;
}
function formatMailMultipartDigest( $part )
{
$t = '';
foreach ( $part->getParts() as $key => $alternativePart )
{
$t .= "-DIGEST-$key-----------------------------------------------------------------\n";
$t .= formatMailPart( $alternativePart );
}
$t .= "-DIGEST END---------------------------------------------------------\n";
return $t;
}
function formatMailRfc822Digest( $part )
{
$t = '';
$t .= "-DIGEST-ITEM-$key------------------------------------------------------------\n";
$t .= "Item:\n\n";
$t .= formatMailpart( $part->mail );
$t .= "-DIGEST ITEM END----------------------------------------------------\n";
return $t;
}
function formatMailMultipartAlternative( $part )
{
$t = '';
foreach ( $part->getParts() as $key => $alternativePart )
{
$t .= "-ALTERNATIVE ITEM $key-------------------------------------------------------\n";
$t .= formatMailPart( $alternativePart );
}
$t .= "-ALTERNATIVE END----------------------------------------------------\n";
return $t;
}
function formatMailText( $part )
{
$t = '';
$t .= "Original Charset: {$part->originalCharset}\n";
$t .= "Charset: {$part->charset}\n";
$t .= "Encoding: {$part->encoding}\n";
$t .= "Type: {$part->subType}\n";
$t .= "\n{$part->text}\n";
return $t;
}
function formatMailFile( $part )
{
$t = '';
$t .= "Disposition Type: {$part->dispositionType}\n";
$t .= "Content Type: {$part->contentType}\n";
$t .= "Mime Type: {$part->mimeType}\n";
$t .= "Content ID: {$part->contentId}\n";
$t .= "Filename: {$part->fileName}\n";
$t .= "\n";
return $t;
}
function formatAddresses( $addresses )
{
$fa = array();
foreach ( $addresses as $address )
{
$fa[] = formatAddress( $address );
}
return implode( ', ', $fa );
}
function formatAddress( $address )
{
$name = '';
if ( !empty( $address->name ) )
{
$name = "{$address->name} ";
}
return $name . "<{$address->email}>";
} |


Sir,
I am from India/Kerala and I like all your codes and interested to study something from you !
Plz mail me
AA
hi i am from paistan and i wanted ot get the source code of php and interest to learn some thing
Good one mate.. your site have some real good stuff!!! Keep up the good work
how can a word file can be viewed as html using php?
HEY i m from india and ur site is too good i want to make a php site with some amazing stuff could u give me some idea , like about a site and what features it should contain
thanks and regards
kapil waiting for reply
Perhaps, you can start a PHP website with new generation integration such as PHP + AS3, PHP + Adobe Air, or Flex etc. Better you find one.
sure i do thanks a lot ,keep it up! love ur site -KAPIL