PHP code example of pavlinter / yii2-adm-email-config

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

    

pavlinter / yii2-adm-email-config example snippets


'on beforeRequest' => function ($event) {
    \pavlinter\admeconfig\models\EmailConfig::changeMailConfig();
},
'modules' => [
    ...
    'adm' => [
        ...
        'modules' => [
            'admeconfig'
        ],
        ...
    ],
    'admeconfig' => [
        'class' => 'pavlinter\admeconfig\Module',
    ],
    ...
],
'components' => [
    ...
    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
    ],
    ...
],

yii migrate --migrationPath=@vendor/pavlinter/yii2-adm-email-config/admeconfig/migrations

Yii::$app->mailer->compose()
    ->setTo('[email protected]')
    ->setFrom(Yii::$app->params['adminEmailName'])
    //->setFrom([Yii::$app->params['adminEmail'] => Yii::$app->params['adminName']])
    ->setSubject('subject')
    ->setHtmlBody('body')
    ->send();

$valid = EmailConfig::eachEmail(function ($email) {
    return Yii::$app->mailer->compose()
        ->setTo($email)
        ->setFrom()
        ->setSubject('Subject')
        ->setHtmlBody('Body')
        ->send();
});
if ($valid === false) {
    return false;
}
return true;