You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
701 B

7 years ago
<?php
namespace core\services;
use core\forms\ContactForm;
3 years ago
use RuntimeException;
7 years ago
use yii\mail\MailerInterface;
class ContactService
{
3 years ago
private string $adminEmail;
private MailerInterface $mailer;
7 years ago
public function __construct($adminEmail, MailerInterface $mailer)
{
$this->adminEmail = $adminEmail;
$this->mailer = $mailer;
}
public function send(ContactForm $form): void
{
$sent = $this->mailer->compose()
->setTo($this->adminEmail)
->setSubject($form->subject)
->setTextBody($form->body)
->send();
if (!$sent) {
3 years ago
throw new RuntimeException('Sending error.');
7 years ago
}
}
3 years ago
}