PHP code example of tigrov / yii2-email-reply

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


    class Model extends yii\db\ActiveRecord implements tigrov\emailReply\ModelInterface
    {
        use tigrov\yii2\emailReply\ActiveRecordThread;
    
        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 
        }
    }
    

    return [
        ...
        'emailReply' => [
            'class' => 'tigrov\emailReply\EmailReply',
            'classesMap' => [
                // key will be used as prefix for email address
                'm' => \Model::class,
            ],
        ],
        ...
    ];
    

    $replyEmail = \Yii::$app->emailReply->getReplyEmail($model);
    
    // Send an email to somebody using the reply email address
    $message = \Yii::$app->mailer->compose($view)
        ->setReplyTo([$replyEmail => \Yii::$app->name])
        ->setFrom([$replyEmail => \Yii::$app->name]);
     
    // Set message subject, body, recipients and etc
    ...
 
    $message->send();
    

    class EmailReplyController extends tigrov\yii2\emailReply\EmailReplyController
    {
    }
    

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