Skip to content

Commit

Permalink
Backport Mailgun endpoint fix (laravel#26592)
Browse files Browse the repository at this point in the history
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: laravel#26576
Original fix: laravel#24994
  • Loading branch information
driesvints authored and taylorotwell committed Nov 22, 2018
1 parent 0a02938 commit 79f34c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/Illuminate/Mail/Transport/MailgunTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ class MailgunTransport extends Transport
*
* @var string
*/
protected $url;
protected $endpoint;

/**
* Create a new Mailgun transport instance.
*
* @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);
}

Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion src/Illuminate/Mail/TransportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ protected function createMailgunDriver()

return new MailgunTransport(
$this->guzzle($config),
$config['secret'], $config['domain']
$config['secret'],
$config['domain'],
$config['endpoint'] ?? null
);
}

Expand Down

0 comments on commit 79f34c8

Please sign in to comment.