Skip to content

Commit

Permalink
Add reply-to on config for Mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
m-tatsuto authored and taylorotwell committed Dec 15, 2016
1 parent 8949a03 commit 4f38130
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Illuminate/Mail/MailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public function register()
if (is_array($to) && isset($to['address'])) {
$mailer->alwaysTo($to['address'], $to['name']);
}

$replyTo = $app['config']['mail.reply-to'];

if (is_array($replyTo) && isset($replyTo['address'])) {
$mailer->alwaysReplyTo($replyTo['address'], $replyTo['name']);
}

return $mailer;
});
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class Mailer implements MailerContract, MailQueueContract
* @var array
*/
protected $to;

/**
* The global reply-to address and name.
*
* @var array
*/
protected $replyTo;

/**
* The IoC container instance.
Expand Down Expand Up @@ -111,6 +118,18 @@ public function alwaysTo($address, $name = null)
{
$this->to = compact('address', 'name');
}

/**
* Set the global reply-to address and name.
*
* @param string $address
* @param string|null $name
* @return void
*/
public function alwaysReplyTo($address, $name = null)
{
$this->replyTo = compact('address', 'name');
}

/**
* Begin the process of mailing a mailable class instance.
Expand Down Expand Up @@ -416,6 +435,13 @@ protected function createMessage()
if (! empty($this->from['address'])) {
$message->from($this->from['address'], $this->from['name']);
}

// If a global reply-to address has been specified we will set it on every message
// instances so the developer does not have to repeat themselves every time
// they create a new message. We will just go ahead and push the address.
if (! empty($this->replyTo['address'])) {
$message->replyTo($this->replyTo['address'], $this->replyTo['name']);
}

return $message;
}
Expand Down

0 comments on commit 4f38130

Please sign in to comment.