Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reply-to on config for Mailer #16810

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Illuminate/Mail/MailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function register()
$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 @@ -52,6 +52,13 @@ class Mailer implements MailerContract, MailQueueContract
*/
protected $to;

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

/**
* The IoC container instance.
*
Expand Down Expand Up @@ -112,6 +119,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 @@ -417,6 +436,13 @@ protected function createMessage()
$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