MicroFrameWork/kernel/helpers/SMTP.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2024-12-04 16:28:05 +03:00
<?php
namespace kernel\helpers;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
class SMTP
{
public PHPMailer $mail;
2024-12-04 18:45:17 +03:00
public function __construct()
2024-12-04 16:28:05 +03:00
{
$this->mail = new PHPMailer(true);
2024-12-04 16:37:11 +03:00
$this->mail->CharSet = 'UTF-8';
2024-12-04 16:28:05 +03:00
$this->mail->isSMTP();
$this->mail->SMTPAuth = true;
$this->mail->SMTPDebug = 0;
2024-12-04 18:45:17 +03:00
$this->mail->Host = $_ENV['MAIL_SMTP_HOST'];
$this->mail->Port = $_ENV['MAIL_SMTP_PORT'];
$this->mail->Username = $_ENV['MAIL_SMTP_USERNAME'];
$this->mail->Password = $_ENV['MAIL_SMTP_PASSWORD'];
2024-12-04 16:28:05 +03:00
}
/**
* @throws Exception
*/
2024-12-04 18:45:17 +03:00
public function send_html(array $params)
2024-12-04 16:28:05 +03:00
{
2024-12-04 18:45:17 +03:00
if (!isset($params['address'])){
return false;
}
$this->mail->setFrom($this->mail->Username, $params['from_name'] ?? $this->mail->Host);
$this->mail->addAddress($params['address']);
$this->mail->Subject = $params['subject'] ?? 'Без темы';
$body = $params['body'] ?? 'Нет информации';
2024-12-04 16:28:05 +03:00
$this->mail->msgHTML($body);
$this->mail->send();
}
}