PHP code example of divineomega / email-structure-parser
1. Go to this page and download the library: Download divineomega/email-structure-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
divineomega / email-structure-parser example snippets
use DivineOmega\EmailStructureParser\EmailStructureParser;
// Connect to mailbox
$imapStream = imap_open('{outlook.office365.com:993/ssl/novalidate-cert}INBOX', getenv('USERNAME'), getenv('PASSWORD'));
// Get a message number (in this example, just get the first)
$msgNums = imap_search($imapStream, 'ALL');
$msgNum = $msgNums[0];
// Load message into parser
$parser = new EmailStructureParser($imapStream, $msgNum);
// Get parsed multipart email parts - including plain text and/or HTML content, and any attachments
$parts = $parser->getParts();
// Output HTML email content
var_dump($parts['TEXT/HTML']);
// Save attached PNG images
foreach($parts['IMAGE/PNG'] as $image) {
file_put_contents($image->name, $image->content);
}
foreach($parts['IMAGE/PNG'] as $image) {
// Store the file as in the above example:
file_put_contents($image->name, $image->content);
// You would then want to store this relationship in your database:
echo "{$image->contentId} => {$image->name}\n";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.