PHP code example of frankspress / sg-parser-bundle
1. Go to this page and download the library: Download frankspress/sg-parser-bundle 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/ */
frankspress / sg-parser-bundle example snippets
namespace App\EventSubscriber;
use Frankspress\SgParserBundle\Attachment\NewAttachment;
use Frankspress\SgParserBundle\Event\ParserApiCompleteEvent;
use Frankspress\SgParserBundle\Event\SgParserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SgParseEmail implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
SgParserEvents::PARSER_API => 'onParserApiComplete'
];
}
public function onParserApiComplete(ParserApiCompleteEvent $event )
{
$email = $event->getNewEmail();
$attachments = $event->getNewAttachment();
// SAVE YOUR EMAIL/ATTACHMENTS
}
}
// ...
public function onParserApiComplete(ParserApiCompleteEvent $event )
{
$email = $event->getNewEmail();
$attachments = $event->getNewAttachment();
/*
$email->getAttachment();
$email->getSubject();
$email->getSenderEmail();
$email->getSenderName();
$email->getBody();
*/
if ( !empty($email->getAttachment() ) ) {
foreach ($attachments as $attachment ) {
/*
$attachment->getFile();
$attachment->getFileName();
$attachment->getOriginalFileName();
$attachment->error();
$attachment->getFilePath();
$attachment->getSize();
$attachment->getType();
*/
}
}
}