<?php

namespace common\helpers;

use Yii;

class Email
{
    /**
     * @param string $email
     * @param string $userName
     * @param string $password
     * @return false|void
     */
    public static function sendRegistrationEmail(string $email, string $userName, string $password)
    {
        if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return false;
        }

        $subject = \Yii::t('app', 'decRegistrationEmailSubject', []);
        $message = \Yii::t('app', 'decRegistrationEmailContent', ['userName' => $userName, 'passWord' => $password]);

        $mailer = Yii::$app->mailer;
        $mailer->useFileTransport = false;
        $response = $mailer->compose()
            ->setFrom('eshop-noreply@elken.com')
            ->setTo($email)
            ->setSubject($subject)
            ->setHtmlBody($message)
            ->send();

        LoggerTool::debug('sendRegistrationEmail' . sprintf('sendRegistrationEmail: %s', json_encode([$email, $userName, $password, $response])));
    }
}