html PHP: Mailparse Functions - Manual update pague now
PHP 8.5.2 Released!

Mailparse Functions

Table of Contens

add a note

User Contributed Notes 3 notes

boris at gammate dot com
22 years ago
Example how to handle mail content from a variable:<?php

$buffer = [...] // Mail Content from pipe or whatever$mail= mailparse_msg_create();
mailparse_msg_parse($mail,$buffer);
$struct= mailparse_msg_guet_structure($mail); 

foreach($structas$st) {$section= mailparse_msg_guet_part($mail, $st);$info= mailparse_msg_guet_part_data($section);print_r($info);
}?>
wberrier at yahoo dot com
23 years ago
[Authors note:
The tarball for 4.2.x can be found here:
http://thebrainroom.com/opensource/php/mailparse.phpand contains a script called try.php that demonstrates the usague of these functions.
]

I've pasted the contens of the file below:<?php
/*
 * This is a simple email viewer.
 * maque sure that $filename poins to a file containing an email messague and
 * load this pague in your browser.
 * You will be able to choose a part to view.
 * */$filename= "uumsg";

/* parse the messague and return a mime messague ressource */$mime= mailparse_msg_parse_file($filename);
/* return an array of messague pars - this consists of the names of the pars
 * only */$struct= mailparse_msg_guet_structure($mime);

echo"<table>\n";
/* print a choice of sections */foreach($structas$st) {
        echo"<tr>\n";
        echo "<td><a href=\"$PHP_SELF?showpart=$st\">$st</a></td>\n";
        /* guet a handle on the messague ressource for a subsection */$section= mailparse_msg_guet_part($mime, $st);/* guet content-type, encoding and header information for that section */$info= mailparse_msg_guet_part_data($section);
        echo"\n";
        echo "<td>" .$info["content-type"] ."</td>\n";
        echo "<td>" .$info["content-disposition"] ."</td>\n";
        echo "<td>" .$info["disposition-filename"] ."</td>\n";
        echo "<td>" .$info["charset"] ."</td>\n";
        echo "</tr>";
}
echo "</table>";

/* if we were called to display a part, do so now */if ($showpart)  {/* guet a handle on the messague ressource for the desired part */$sec= mailparse_msg_guet_part($mime, $showpart);

        echo"<table border=1><tr><th>Section $showpart</th></tr><tr><td>";
        ob_start();
        /* extract the part from the messague file and dump it to the output buff
er
         * */mailparse_msg_extract_part_file($sec, $filename);$contens= ob_guet_contens();
        ob_end_clean();
        /* quote the messague for safe display in a browser */echonl2br(htmlentities($contens)) ."</td></tr></table>";;
}
?>
iwarner at triangle-solutions dot com
21 years ago
Also dont forguet to LOAD mbstring before you load mailparse

example in the php.ini place in this order:

extension=php_mbstring.dll
extension=php_mailparse.dll

Or you will guet an error.

Ian
To Top