<?php


class EmailValidate{
    public function __construct($registry)
    {
        $this->config = $registry->get('config');
        $this->db = $registry->get('db');
        $this->request = $registry->get('request');
    }

    public function sendEmail($email, $name, $subject, $message)
    {
        try {
            $mail = new Mail();
            $mail->protocol = $this->config->get('futura_email_noreply_protocol');
            $mail->parameter = $this->config->get('futura_email_noreply_parameter');
            $mail->hostname = $this->config->get('futura_email_noreply_hostname');
            $mail->username = $this->config->get('futura_email_noreply_username');
            $mail->password = Crypto::descriptografarAES256($this->config->get('futura_email_noreply_password'), Crypto::CAES256);
            $mail->port = $this->config->get('futura_email_noreply_port');
            $mail->timeout = $this->config->get('futura_email_noreply_timeout');
            $mail->setFrom($this->config->get('futura_email_noreply_username'));
            $mail->setTo($email);
            $mail->setSender($name);
            $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
            $mail->setHtml($message);
            $mail->send(true);

        }catch (Exception $e){
            $this->error['warning'] = 'Erro ao enviar o email de validação, tente novamente mais tarde!';
            if ($this->config->get('config_error_log')) {
                $this->log->write('Error ao reenviar senha admin: ' . $e);
            }
        }
    }

}