<?php

namespace App\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Services;

class TestEmail extends BaseCommand
{
    protected $group = 'Email';
    protected $name = 'email:test';
    protected $description = 'Test Gmail SMTP';

    public function run(array $params)
    {
        $email = Services::email();

        $email->setFrom('drehan566@gmail.com', 'CNC');
        $email->setTo('kelas2543@gmail.com');

        $email->setSubject('SMTP Test');

        $email->setMessage('SMTP Gmail berhasil.');

        if ($email->send()) {

            CLI::write('EMAIL BERHASIL DIKIRIM', 'green');

        } else {

            CLI::error($email->printDebugger([
                'headers',
                'subject',
                'body'
            ]));

        }
    }
}