Skip to content

Commit

Permalink
Replace mailer from Swift to Symfony, fix SMTP mail sending (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
devanych committed Aug 26, 2021
1 parent 01d5cac commit 8801574
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -52,8 +52,8 @@
"yiisoft/injector": "^1.0",
"yiisoft/log": "^1.0",
"yiisoft/log-target-file": "^1.0",
"yiisoft/mailer": "^2.0",
"yiisoft/mailer-swiftmailer": "^2.0",
"yiisoft/mailer": "^3.0",
"yiisoft/mailer-symfony": "dev-master",
"yiisoft/rbac": "^3.0@dev",
"yiisoft/rbac-php": "^3.0@dev",
"yiisoft/router": "^3.0@dev",
Expand Down
1 change: 1 addition & 0 deletions config/params.php
Expand Up @@ -5,6 +5,7 @@
return [
'mailer' => [
'adminEmail' => 'admin@example.com',
'senderEmail' => 'sender@example.com',
],

'yiisoft/aliases' => [
Expand Down
1 change: 1 addition & 0 deletions config/web/contact-mailer.php
Expand Up @@ -10,6 +10,7 @@
ContactMailer::class => [
'class' => ContactMailer::class,
'__construct()' => [
'sender' => $params['mailer']['senderEmail'],
'to' => $params['mailer']['adminEmail'],
],
],
Expand Down
4 changes: 4 additions & 0 deletions src/Contact/ContactMailer.php
Expand Up @@ -21,17 +21,20 @@ class ContactMailer
private FlashInterface $flash;
private LoggerInterface $logger;
private MailerInterface $mailer;
private string $sender;
private string $to;

public function __construct(
FlashInterface $flash,
LoggerInterface $logger,
MailerInterface $mailer,
string $sender,
string $to
) {
$this->flash = $flash;
$this->logger = $logger;
$this->mailer = $mailer->withTemplate(new MessageBodyTemplate(__DIR__ . '/mail/'));
$this->sender = $sender;
$this->to = $to;
}

Expand All @@ -45,6 +48,7 @@ public function send(FormModelInterface $form, ServerRequestInterface $request)
)
->withSubject($form->getAttributeValue('subject'))
->withFrom([$form->getAttributeValue('email') => $form->getAttributeValue('name')])
->withSender($this->sender)
->withTo($this->to);

$attachFiles = $request->getUploadedFiles();
Expand Down

0 comments on commit 8801574

Please sign in to comment.