simple family
3 May
Salah satu cara untuk nge-parsing sebuah message e-mail menggunakan PHP adalah memakai library MailParse. Untuk menggunakan MailParse, Anda harus meng-configure php dengan –enable-mailparse. Kemudian download MailParse dan meng-compile-nya.
Kalo langkah-langkah di atas sudah dilakukan, coba script di bawah. Parsing ini juga akan berlaku jika Anda akan membuat interface dengan MMSC menggunakan MM7 standar, karena MM7 standar tersebut mempunyai format yang hampir sama dengan e-mail.
Selamat mencoba.
[php] /*
* This is a simple email viewer.
* make sure that $filename points to a file containing an email message and
* load this page in your browser.
* You will be able to choose a part to view.
*/
#$filename = “/home/CLIENTWEB/worlddo/mimetests/namib.rfc822″;
$filename = “/home/CLIENTWEB/worlddo/mimetests/uumsg”;
#$filename = “/home/CLIENTWEB/worlddo/mimetests/segblob.txt”;
#$filename = “yourmessage.txt”;
/* parse the message and return a mime message resource */
$mime = mailparse_msg_parse_file($filename);
/* return an array of message parts - this contsists of the names of the parts only */
$struct = mailparse_msg_get_structure($mime);
echo ”
| $st | ” . $info[”content-type”] . “ | ” . $info[”content-disposition”] . “ | ” . $info[”disposition-filename”] . “ | ” . $info[”charset”] . “ |
“;
/* if we were called to display a part, do so now */
if ($showpart) {
/* get a handle on the message resource for the desired part */
$sec = mailparse_msg_get_part($mime, $showpart);
echo ”
| Section $showpart |
|---|
| “; ob_start(); /* extract the part from the message file and dump it to the output buffer */ mailparse_msg_extract_part_file($sec, $filename); $contents = ob_get_contents(); ob_end_clean(); /* quote the message for safe display in a browser */ echo nl2br(htmlentities($contents)) . “ |
“;;
}
?>[/php]
Leave a reply