This commit is contained in:
Билай Станислав 2024-12-04 16:37:11 +03:00
parent 15c801f579
commit d318c99ba5

View File

@ -8,21 +8,17 @@ use PHPMailer\PHPMailer\PHPMailer;
class SMTP class SMTP
{ {
public PHPMailer $mail; public PHPMailer $mail;
public string $host;
public int $port;
public string $username;
public string $password;
public function __construct(array $config = []) public function __construct(array $config = [])
{ {
$this->mail = new PHPMailer(true); $this->mail = new PHPMailer(true);
$this->mail->CharSet = 'UTF-8';
$this->mail->isSMTP(); $this->mail->isSMTP();
$this->mail->SMTPAuth = true; $this->mail->SMTPAuth = true;
$this->mail->SMTPDebug = 0; $this->mail->SMTPDebug = 0;
$this->host = $config['host'] ?? ''; $this->mail->Host = $config['host'] ?? '';
$this->port = $config['port'] ?? 587; $this->mail->Port = $config['port'] ?? 587;
$this->username = $config['username'] ?? ''; $this->mail->Username = $config['username'] ?? '';
$this->password = $config['password'] ?? ''; $this->mail->Password = $config['password'] ?? '';
} }
/** /**
@ -30,7 +26,7 @@ class SMTP
*/ */
public function send(string $address): void public function send(string $address): void
{ {
$this->mail->setFrom($this->username, $this->host); $this->mail->setFrom($this->mail->Username, $this->mail->Host);
$this->mail->addAddress($address); $this->mail->addAddress($address);
$this->mail->Subject = 'Код подтверждения'; $this->mail->Subject = 'Код подтверждения';
$body = '<p><strong>«Hello, world!» </strong></p>'; $body = '<p><strong>«Hello, world!» </strong></p>';