PHP code example of tigrov / email-reply

1. Go to this page and download the library: Download tigrov/email-reply 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/ */

    

tigrov / email-reply example snippets


    class Model implements ModelInterface
    {
        public static function paramNames() {}
    
        public function paramValues() {}
    
        public static function buildFromParams($paramValues) {}
    
        public function emailReply($message) {}
    }
    

    $config = [
        'classesMap' => [
            // key will be used as prefix for email address
            'model' => \Model::class,
            // email for reply will be like [email protected]
            // or
            // 'm' => \Model::class,
            // email for reply will be like [email protected]
            // where 5 is id of a model
        ],
    ];
 
    $emailReply = new EmailReply($config);
    

    $email = $emailReply->getReplyEmail($model, 'domain.com');
    
    // Send an email to somebody with the reply email $email
    // ...
    

    $server = new Server($host, $port);
    
    $connection = $server->authenticate($username, $password);
    
    $mailboxModels = Reader::getMailboxModels($connection);
    
    $messages = Reader::getIterator($mailboxModels);
    
    $emailReply->read($messages);
    
    $connection->expunge();
    

    class Model implements ModelInterface
    {
        // ...
    
        public function emailReply($message)
        {
            /** @var string $fromEmail email address of the sender */
            $fromEmail = $message->getFrom()->getAddress();
            
            /** @var string $fromName name of the sender */
            $fromName = $message->getFrom()->getName();
            
            /** @var string $content content from the replied message */
            $content = $message->getBodyHtml() ?: $message->getBodyText() ?: $message->getDecodedContent();
            
            // Parse the content to get only answer
            $content = EmailReplyParser::parseReply($content);
            
            // To do something with $content
            // e.g. add comment from $fromEmail to the object 
        }
    

$reply = EmailReplyParser::parseReply($content);