Skip to content

Commit

Permalink
Merge pull request #6 from alfedorenko/master
Browse files Browse the repository at this point in the history
Add replyTo to message and mandrill mailer
  • Loading branch information
aprokopenko authored Jul 31, 2018
2 parents a520728 + 6a3ae20 commit ca433df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/DataObjects/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class MailMessage extends DataObject
*/
protected $to;

/**
* Property with Reply-To email
*
* @var EmailAddress
*/
protected $replyTo;

/**
* Property with Cc email
*
Expand Down Expand Up @@ -102,6 +109,9 @@ public function __construct(array $config)
if ($this->from) {
$this->from = new EmailAddress($this->from);
}
if ($this->replyTo) {
$this->replyTo = new EmailAddress($this->replyTo);
}

// convert recipients to Data objects.
foreach (array('to', 'cc', 'bcc') as $key) {
Expand Down Expand Up @@ -135,6 +145,16 @@ public function getTo()
return $this->to;
}

/**
* Getting email Reply To
*
* @return EmailAddress
*/
public function getReplyTo()
{
return $this->replyTo;
}

/**
* Getting email CC
*
Expand Down
11 changes: 9 additions & 2 deletions src/Mailer/MandrillMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function send(MailMessage $message)
'from_email' => $message->getFrom()->getEmail(),
'from_name' => $message->getFrom()->getName(),
);

$replyTo=$message->getReplyTo();
if(!empty($replyTo)) {
$mandrillMessage['headers']=['Reply-To' => $replyTo->getEmail()];
}

// Recipients.
$recipients = [
Expand All @@ -71,7 +76,9 @@ public function send(MailMessage $message)

$to = [];
foreach ($recipients as $type => $emails) {
if (empty($emails)) continue;
if (empty($emails)) {
continue;
}
foreach ($emails as $email) {
$to[] = [
'email' => $email->getEmail(),
Expand All @@ -85,7 +92,7 @@ public function send(MailMessage $message)

// Attachments.
if (0 < $message->getAttachmentsSize() && $message->getAttachmentsSize() < $this->attachmentsSizeLimit
&& $attachments = $message->getAttachments()
&& $attachments = $message->getAttachments()
) {
$attachmentsArray = [];
foreach ($attachments as $attachment) {
Expand Down
5 changes: 5 additions & 0 deletions src/Mailer/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function send(MailMessage $message)
$mail->setFrom($address->getEmail(), $address->getName());
}

// Set Reply To.
if ($replyTo = $message->getReplyTo()) {
$mail->addReplyTo($replyTo->getEmail(), $replyTo->getName());
}

// Recipients.
if ($to = $message->getTo()) {
foreach ($to as $address) {
Expand Down

0 comments on commit ca433df

Please sign in to comment.