Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is supplementary documentation in the <a href="http://blucel.co.uk/a/mailparse-2.1.5/README" rel="nofollow">README file that comes with the extension</a> including the following OO example which I found helpful.</p> <pre><code>&lt;?php $file = "/path/to/rfc822/compliant/message"; // parse the message in $file. // The file MUST remain in existence until you are finished using // the object, as mailparse does not cache the file in memory. // You can also use two alternative syntaxes: // // Read the message from a variable: // $msg =&amp; new MimeMessage("var", $message); // // Read the message from a stream (from fopen). // The stream MUST be seekable, or things will not work correctly. // Also, you MUST NOT fclose the stream until you have finished // using the message object (or any child objects it returns). // $msg =&amp; new MimeMessage("stream", $fp); // $msg =&amp; new MimeMessage("file", $file); // Process the message. display_part_info("message", $msg); // Little function to display things function display_part_info($caption, &amp;$msgpart) { echo "Message part: $caption\n"; // The data member corresponds to the information // available from the mailparse_msg_get_part_data function. // You can access a particular header like this: // $subject = $msgpart-&gt;data["headers"]["subject"]; var_dump($msgpart-&gt;data); echo "The headers are:\n"; // Display the headers (in raw format) to the browser output. // You can also use: // $msgpart-&gt;extract_headers(MAILPARSE_EXTRACT_STREAM, $fp); // to write the headers to the supplied stream at it's current // position. // // $var = $msgpart-&gt;extract_headers(MAILPARSE_EXTRACT_RETURN); // to return the headers in a variable. $msgpart-&gt;extract_headers(MAILPARSE_EXTRACT_OUTPUT); // Display the body if this part is intended to be displayed: $n = $msgpart-&gt;get_child_count(); if ($n == 0) { // Return the body as a string (the MAILPARSE_EXTRACT parameter // acts just as it does in extract_headers method. $body = $msgpart-&gt;extract_body(MAILPARSE_EXTRACT_RETURN); echo htmlentities($body); // This function tells you about any uuencoded attachments // that are present in this part. $uue = $msgpart-&gt;enum_uue(); if ($uue !== false) { var_dump($uue); foreach($uue as $index =&gt; $data) { // $data =&gt; array("filename" =&gt; "original filename", // "filesize" =&gt; "size of extracted file", // ); printf("UUE[%d] %s (%d bytes)\n", $index, $data["filename"], $data["filesize"]); // Display the extracted part to the output. $msgpart-&gt;extract_uue($index, MAILPARSE_EXTRACT_OUTPUT); } } } else { // Recurse and show children of that part for ($i = 0; $i &lt; $n; $i++) { $part =&amp; $msgpart-&gt;get_child($i); display_part_info("$caption child $i", $part); } } } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload