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.
Mailparse
- 導入
- インストール/設定
- 定義済み定数
- Mailparse 関数
- mailparse_determine_best_xfer_encoding — 最も適したエンコーディングを取得する
- mailparse_msg_create — mime メールリソースを作成する
- mailparse_msg_extract_part_file — メッセージセクションを展開/デコードする
- mailparse_msg_extract_part — メッセージセクションを展開/デコードする
- mailparse_msg_extract_whole_part_file — ヘッダを含むメッセージセクションを、transfer encoding をデコードせずに展開する
- mailparse_msg_free — MIME リソースを解放する
- mailparse_msg_get_part_data — メッセージに関する情報の連想配列を返す
- mailparse_msg_get_part — MIME メッセージの指定したセクションに関するハンドルを返す
- mailparse_msg_get_structure — 指定したメッセージ内の MIME セクション名の配列を返す
- mailparse_msg_parse_file — ファイルをパースする
- mailparse_msg_parse — データをパースし、バッファに追加する
- mailparse_rfc822_parse_addresses — RFC 822 準拠のアドレスをパースする
- mailparse_stream_encode — ソースファイルポインタからストリームデータを取得し、 エンコーディングを適用し、出力ファイルポインタに書き込む
- mailparse_uudecode_all — ファイルポインタからデータをスキャンし、uuencode されたファイルを展開する
gabe at fijiwebdesign dot com
23-Oct-2010 11:57
