downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

導入> <mail
[edit] Last updated: Fri, 11 May 2012

view this page in

Mailparse



add a note add a note User Contributed Notes Mailparse
gabe at fijiwebdesign dot com 23-Oct-2010 11:57
I've put together an open source mail parser class using mailpase functions.
http://code.google.com/p/php-mime-mail-parser/

This should make it more straight forward to parse the email. Example usage:

<?php

// mail parser class
require_once('MimeMailParser.class.php');

$path = 'path/to/mail.txt';
$Parser = new MimeMailParser();
$Parser->setPath($path);

$to = $Parser->getHeader('to');
$from = $Parser->getHeader('from');
$subject = $Parser->getHeader('subject');
$text = $Parser->getMessageBody('text');
$html = $Parser->getMessageBody('html');
$attachments = $Parser->getAttachments();

// saving attachments
$save_dir = '/path/to/save/attachments/';
foreach(
$attachments as $attachment) {
 
// get the attachment name
 
$filename = $attachment->filename;
 
// write the file to the directory you want to save it in
 
if ($fp = fopen($save_dir.$filename, 'w')) {
    while(
$bytes = $attachment->read()) {
     
fwrite($fp, $bytes);
    }
   
fclose($fp);
  }
}

?>

Hope this helps.

 
show source | credits | sitemap | contact | advertising | mirror sites