Skip to content

Commit

Permalink
Merge pull request Sylius#8441 from loic425/feature/mailer/add-reply-to
Browse files Browse the repository at this point in the history
[Mailer] add reply-to on contact request email
  • Loading branch information
pjedrzejewski committed Aug 31, 2017
2 parents fbb5020 + 4d20628 commit a4381b2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions UPGRADE.md
Expand Up @@ -60,6 +60,7 @@
### Mailer / MailerBundle

* `Email` has been made final, use decoration instead of extending it.
* `SenderInterface::send` method has changed to add `replyTo` argument

### Order / OrderBundle

Expand Down
Expand Up @@ -50,12 +50,14 @@ public function send(
RenderedEmail $renderedEmail,
EmailInterface $email,
array $data,
array $attachments = []
array $attachments = [],
array $replyTo = []
): void {
$message = (new \Swift_Message())
->setSubject($renderedEmail->getSubject())
->setFrom([$senderAddress => $senderName])
->setTo($recipients)
->setReplyTo($replyTo);
;

$message->setBody($renderedEmail->getBody(), 'text/html');
Expand All @@ -66,7 +68,7 @@ public function send(
$message->attach($file);
}

$emailSendEvent = new EmailSendEvent($message, $email, $data, $recipients);
$emailSendEvent = new EmailSendEvent($message, $email, $data, $recipients, $replyTo);

$this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_SEND, $emailSendEvent);

Expand Down
Expand Up @@ -39,6 +39,6 @@ public function __construct(SenderInterface $emailSender)
*/
public function sendContactRequest(array $data, array $recipients): void
{
$this->emailSender->send(Emails::CONTACT_REQUEST, $recipients, ['data' => $data]);
$this->emailSender->send(Emails::CONTACT_REQUEST, $recipients, ['data' => $data], [], [$data['email']]);
}
}
Expand Up @@ -43,7 +43,9 @@ function it_sends_a_contact_request_email(SenderInterface $sender): void
'email' => 'customer@example.com',
'message' => 'Hello!',
],
]
],
[],
['customer@example.com']
)
->shouldBeCalled()
;
Expand Down
16 changes: 15 additions & 1 deletion src/Sylius/Component/Mailer/Event/EmailSendEvent.php
Expand Up @@ -41,18 +41,24 @@ final class EmailSendEvent extends Event
*/
protected $data;

/**
* @var string[]
*/
protected $replyTo;

/**
* @param mixed $message
* @param array $recipients
* @param EmailInterface $email
* @param array $data
*/
public function __construct($message, EmailInterface $email, array $data, array $recipients = [])
public function __construct($message, EmailInterface $email, array $data, array $recipients = [], array $replyTo = [])
{
$this->message = $message;
$this->email = $email;
$this->data = $data;
$this->recipients = $recipients;
$this->replyTo = $replyTo;
}

/**
Expand Down Expand Up @@ -86,4 +92,12 @@ public function getData(): array
{
return $this->data;
}

/**
* @return string[]
*/
public function getReplyTo(): array
{
return $this->replyTo;
}
}
Expand Up @@ -31,6 +31,7 @@ interface AdapterInterface
* @param EmailInterface $email
* @param array $data
* @param array $attachments
* @param array $replyTo
*/
public function send(
array $recipients,
Expand All @@ -39,6 +40,7 @@ public function send(
RenderedEmail $renderedEmail,
EmailInterface $email,
array $data,
array $attachments = []
array $attachments = [],
array $replyTo = []
): void;
}
5 changes: 3 additions & 2 deletions src/Sylius/Component/Mailer/Sender/Sender.php
Expand Up @@ -66,7 +66,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function send(string $code, array $recipients, array $data = [], array $attachments = []): void
public function send(string $code, array $recipients, array $data = [], array $attachments = [], array $replyTo = []): void
{
$email = $this->provider->getEmail($code);

Expand All @@ -86,7 +86,8 @@ public function send(string $code, array $recipients, array $data = [], array $a
$renderedEmail,
$email,
$data,
$attachments
$attachments,
$replyTo
);
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Component/Mailer/Sender/SenderInterface.php
Expand Up @@ -24,5 +24,5 @@ interface SenderInterface
* @param array $data
* @param array $attachments
*/
public function send(string $code, array $recipients, array $data = [], array $attachments = []): void;
public function send(string $code, array $recipients, array $data = [], array $attachments = [], array $replyTo = []): void;
}
4 changes: 2 additions & 2 deletions src/Sylius/Component/Mailer/spec/Sender/SenderSpec.php
Expand Up @@ -50,7 +50,7 @@ function it_sends_an_email_through_the_adapter(
$data = ['foo' => 2];

$rendererAdapter->render($email, ['foo' => 2])->willReturn($renderedEmail);
$senderAdapter->send(['john@example.com'], 'sender@example.com', 'Sender', $renderedEmail, $email, $data, [])->shouldBeCalled();
$senderAdapter->send(['john@example.com'], 'sender@example.com', 'Sender', $renderedEmail, $email, $data, [], [])->shouldBeCalled();

$this->send('bar', ['john@example.com'], $data, []);
}
Expand All @@ -65,7 +65,7 @@ function it_does_not_send_disabled_emails(
$email->isEnabled()->willReturn(false);

$rendererAdapter->render($email, ['foo' => 2])->shouldNotBeCalled();
$senderAdapter->send(['john@example.com'], 'mail@sylius.org', 'Sylius Mailer', null, $email, [], [])->shouldNotBeCalled();
$senderAdapter->send(['john@example.com'], 'mail@sylius.org', 'Sylius Mailer', null, $email, [], [], [])->shouldNotBeCalled();

$this->send('bar', ['john@example.com'], ['foo' => 2], []);
}
Expand Down

0 comments on commit a4381b2

Please sign in to comment.