From 4e549e301b2b8d2697cd5b7e2c6ce4f03e946e1b Mon Sep 17 00:00:00 2001 From: Andrew Winter Date: Mon, 25 Nov 2019 09:34:18 +0900 Subject: [PATCH] Add support for alternate domains --- src/Mail/Mailer.php | 2 +- src/Mail/Message.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php index 2d27eb8..f3de137 100644 --- a/src/Mail/Mailer.php +++ b/src/Mail/Mailer.php @@ -64,7 +64,7 @@ public function send($view, array $data, Closure $callback, $message = null) $message = $this->message->getMessage(); $files = $this->message->getFiles(); - $domain = $this->config->get('mailgun.domain'); + $domain = $this->message->getDomain(); $response = new Response($this->mailgun->post("{$domain}/messages", $message, $files)); return $response; diff --git a/src/Mail/Message.php b/src/Mail/Message.php index 4f71fdd..bb9a8e8 100644 --- a/src/Mail/Message.php +++ b/src/Mail/Message.php @@ -18,6 +18,11 @@ class Message */ protected $variables = []; + /** + * @var string|null + */ + protected $domain = null; + /** * Message constructor. * @@ -281,6 +286,30 @@ public function testmode($enabled = true) return $this; } + /** + * Override the default Mailgun domain with another domain name registered with Mailgun. + * + * @param string $domain + * + * @return void + */ + public function domain($domain) + { + $this->domain = $domain; + + return $this; + } + + /** + * Returns the domain name to use to send the message + * + * @return string + */ + public function getDomain() + { + return $this->domain !== null ? $this->domain : $this->config->get('mailgun.domain'); + } + /** * Append a custom MIME header to a message. *