From 79f34c859046c3ddecede41377ab2a75e208548b Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 22 Nov 2018 15:28:00 +0100 Subject: [PATCH] Backport Mailgun endpoint fix (#26592) This was fixed for 5.7 but backporting this to 5.5 wouldn't leave all the LTS folks in the dark who still want to use the EU region. Issue: https://github.com/laravel/framework/issues/26576 Original fix: https://github.com/laravel/framework/pull/24994 --- .../Mail/Transport/MailgunTransport.php | 15 ++++++++++----- src/Illuminate/Mail/TransportManager.php | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Mail/Transport/MailgunTransport.php b/src/Illuminate/Mail/Transport/MailgunTransport.php index bac829327e7f..0b40df79028a 100644 --- a/src/Illuminate/Mail/Transport/MailgunTransport.php +++ b/src/Illuminate/Mail/Transport/MailgunTransport.php @@ -33,7 +33,7 @@ class MailgunTransport extends Transport * * @var string */ - protected $url; + protected $endpoint; /** * Create a new Mailgun transport instance. @@ -41,12 +41,15 @@ class MailgunTransport extends Transport * @param \GuzzleHttp\ClientInterface $client * @param string $key * @param string $domain + * @param string|null $endpoint * @return void */ - public function __construct(ClientInterface $client, $key, $domain) + public function __construct(ClientInterface $client, $key, $domain, $endpoint = null) { $this->key = $key; $this->client = $client; + $this->endpoint = $endpoint ?? 'api.mailgun.net'; + $this->setDomain($domain); } @@ -61,7 +64,11 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul $message->setBcc([]); - $this->client->post($this->url, $this->payload($message, $to)); + $this->client->request( + 'POST', + "https://{$this->endpoint}/v3/{$this->domain}/messages.mime", + $this->payload($message, $to) + ); $this->sendPerformed($message); @@ -161,8 +168,6 @@ public function getDomain() */ public function setDomain($domain) { - $this->url = 'https://api.mailgun.net/v3/'.$domain.'/messages.mime'; - return $this->domain = $domain; } } diff --git a/src/Illuminate/Mail/TransportManager.php b/src/Illuminate/Mail/TransportManager.php index 782d2d39231c..ff677c4c74e0 100644 --- a/src/Illuminate/Mail/TransportManager.php +++ b/src/Illuminate/Mail/TransportManager.php @@ -118,7 +118,9 @@ protected function createMailgunDriver() return new MailgunTransport( $this->guzzle($config), - $config['secret'], $config['domain'] + $config['secret'], + $config['domain'], + $config['endpoint'] ?? null ); }