MicroFrameWork/kernel/helpers/SMTP.php

37 lines
1.0 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;
public function __construct(array $config = [])
{
$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 16:37:11 +03:00
$this->mail->Host = $config['host'] ?? '';
$this->mail->Port = $config['port'] ?? 587;
$this->mail->Username = $config['username'] ?? '';
$this->mail->Password = $config['password'] ?? '';
2024-12-04 16:28:05 +03:00
}
/**
* @throws Exception
*/
public function send(string $address): void
{
2024-12-04 16:37:11 +03:00
$this->mail->setFrom($this->mail->Username, $this->mail->Host);
2024-12-04 16:28:05 +03:00
$this->mail->addAddress($address);
$this->mail->Subject = 'Код подтверждения';
$body = '<p><strong>«Hello, world!» </strong></p>';
$this->mail->msgHTML($body);
$this->mail->send();
}
}