PHP code example of black-lamp / yii2-email-templates

1. Go to this page and download the library: Download black-lamp/yii2-email-templates 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/ */

    

black-lamp / yii2-email-templates example snippets


'modules' => [
     // ...
     'email-templates' => [
         'class' => bl\emailTemplates\EmailTemplates::class,
         'languageProvider' => [
            'class' => bl\emailTemplates\providers\DbLanguageProvider::class,
            'tableName' => 'language',
            'idField' => 'id',
            'nameField' => 'name'
         ]
     ],
]

'components' => [
    // ...
    'emailTemplates' => [
        'class' => bl\emailTemplates\components\TemplateManager::class
    ],
]

$template = Yii::$app->templateManager->getTemplate('test', 1);

    $template->parseSubject([
        '{sitename}' => $sitename
    ]);
    
    $template->parseBody([
        '{username}' => Yii::$app->user->identity->firstname,
        '{link}' => Url::toRoute(['/confirm', 'token' => $token], true)
    ]);

Yii::$app->mailer->compose()
    // ...
    ->setSubject($template->subject)
    ->setHtmlBody($template->body)
    // ...