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.

31 lines
656 B

7 years ago
<?php
namespace core\services;
use core\forms\ContactForm;
use yii\mail\MailerInterface;
class ContactService
{
private $adminEmail;
private $mailer;
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) {
throw new \RuntimeException('Sending error.');
}
}
}