PHP code example of netcore / module-email

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

    

netcore / module-email example snippets


    use Modules\Email\Models\AutomatedEmail;
    use Netcore\Translator\Helpers\TransHelper;
    
    $emails = [
         [
             'key'          => 'verify_email',
             'period'       => 'now',
             'type'         => 'static', // Available types: static, period, interval
             'is_active'    => true,
             'translations' => [
                 'name' => 'Email verification',
                 'text' => 'Please verify your email by clicking on the link: <a href="[VERIFICATION_URL]">[VERIFICATION_URL]</a>'
             ]
         ]
     ];
    
     foreach ($emails as $email) {
         $emailModel = AutomatedEmail::create(array_except($email, 'translations'));
    
         $translations = [];
         foreach (TransHelper::getAllLanguages() as $language) {
             $translations[$language->iso_code] = $email['translations'];
         }
         
         $emailModel->updateTranslations($translations);
     }
 

    email()->subscribe('[email protected]');
    email()->unsubscribe('[email protected]');

    email()->send('verify_email', $user, [
        'VERIFICATION_URL' => $verificationUrl
    ]);

    php artisan module:publish Email
    php artisan module:publish-config Email
    php artisan module:publish-migration Email
    php artisan migrate

    public function getFilters()
    {
        return [
            'is_email_verified' => [
                'name'   => 'Email verified?',
                'type'   => 'select', // Available types: text, select, multi-select, from-to
                'values' => [-1 => 'Not important', 1 => 'Yes', 0 => 'No']
            ],
            'country'           => [
                'name'   => 'Country',
                'type'   => 'multi-select', // Available types: text, select, multi-select, from-to
                'values' => Country::all()->mapWithKeys(function ($country) {
                    return [
                        $country->id => $country->name
                    ];
                })
            ],
        ];
    }
    
    public function getFilterQuery()
    {
        $filters = request()->get('filters', []);
        $query = User::select('id', 'email');
        
        foreach ($this->getFilters() as $field => $filter) {
            $data = (isset($filters[$field])) ? $filters[$field] : -1;
            
            if ($data < 0) {
                continue;
            }
    
            if ($filter['type'] == 'multi-select') {
                $query->whereHas($field, function ($q) use ($data) {
                    $q->whereIn('id', $data);
                });
            } elseif ($filter['type'] == 'from-to') {

                if (($data['from'] && $data['to']) && $data['to'] > $data['from']) {
                    $query->whereBetween($field, [$data['from'], $data['to']]);
                }

            } else {
                $query->where($field, $data);
            }
        }
    
        return $query;
    }