mailgun/mailgun-php

MissingEndpoint exception thrown during sendMessage()

Closed this issue · 6 comments

Haven't done much investigation yet, thought I should report it anyway.

PHP Fatal error: Uncaught exception 'Mailgun\Connection\Exceptions\MissingEndpoint' with message 'The endpoint you've tried to access does not exist. This might be a bug! Notify support@mailgun.com.' in vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php:95
Stack trace:
#0 vendor/mailgun/mailgun-php/src/Mailgun/Connection/RestClient.php(52): Mailgun\Connection\RestClient->responseHandler(Object(Guzzle\Http\Message\Response))
#1 vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(60): Mailgun\Connection\RestClient->post('...', Array, Array)
#2 vendor/mailgun/mailgun-php/src/Mailgun/Mailgun.php(38): Mailgun\Mailgun->post('...', Array, Array)

...

@samholman What code was used that resulted in this error?

@travelton Variables ($from, $to, etc) are passed into the method:

$client = new Mailgun('xxx');

$result = $client->sendMessage(substr(strrchr($from, '@'), 1), array(
    'from'    => $from,
    'to'      => $to,
    'subject' => $subject,
    'text'    => $message,
));

@samholman Copied your code and ran it successfully:

$client = new Mailgun("key-3ax6xnjp29jd6fds4gc373sgvjxteol0");

$from = "test@samples.mailgun.org";
$to = "test@samples.mailgun.org";
$subject = "test";
$message = "testing";

$result = $client->sendMessage(substr(strrchr($from, '@'), 1), array(
    'from'    => $from,
    'to'      => $to,
    'subject' => $subject,
    'text'    => $message,
));

Result:

object(stdClass)#28 (2) {
  ["message"]=>
  string(18) "Queued. Thank you."
  ["id"]=>
  string(48) "<20130905174604.19912.41915@samples.mailgun.org>"
}

Are you sure the domain you're sending from is a valid domain available on the API key you're supplying?

Aha, found what it was - one of our test cases was using an invalid domain (most of the rest of the implementation was OK). Could I suggest perhaps including in that error message something about checking domains against any configured in the account - I don't think it's necessarily totally clear that this needs to be the case.

As a side note, what's the most reliable method of detecting success for the sendMessage() call. The 200 response in http_response_code?

@samholman Yes. Checking the "http_response_code" is the quickest. You can do a quick if statement to ensure a 200 is returned... Or you could simply check to ensure an exception doesn't occur. The SDK will throw an exception if anything goes wrong. And lastly, you could pull the "message id" and store it. The message id will be found in the "http_response_body". I would highly recommend grabbing the message id and storing it. This provides you with an audit trail of sorts.

i get the fallowing error when i recived email and i want to confirm my subscription
when i click on the link so it could check up the hash and put my status as subscribed in mailgun

Hello sami,

You Signed up to our mailing list. Please confirm below.

http://localhost/shoes/mailList/confirm.php?hash=eyJoIjoiNTAxODllOTZiNTU3ZmFkMDcwYTY0ZGVkZDgyZDRmMDg5YzYxODRiMSIsInAiOiJleUp5SWpvaU1URXhOekl3TURVMFFIVnRkQzVsWkhVdWNHc2lMQ0pzSWpvaWJtVjNjMEJ6WVc1a1ltOTRNREZoTjJNelptUTFNVE5sTkRSa1ptSTNaamxsTVRZM01qYzVNemN6TkRJdWJXRnBiR2QxYmk1dmNtY2lmUT09In0%3D

C:\xampp\htdocs\shoes\mailList\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php(146): Mailgun\Connection\RestClient->responseHandler(Object(GuzzleHttp\Message\Response)) #1 C:\xampp\htdocs\shoes\mailList\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(132): Mailgun\Connection\RestClient->put('lists/news@sand...', Array) #2 C:\xampp\htdocs\shoes\mailList\confirm.php(16): Mailgun\Mailgun->put('lists/news@sand...', Array) #3 {main} thrown in C:\xampp\htdocs\shoes\mailList\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php on line 173

mycode for confrim file

validateHash(MAILGUN_SECRET, $_GET['hash']); ``` if($hash) { $list = $hash['mailingList']; $email = $hash['recipientAddress']; $mailgun->put('lists/'. MAILGUN_LIST . '/members' . $email, [ 'subscribed' => 'yes' ]); $mailgun->sendMessage(MAILGUN_DOMAIN,[ 'from' => 'noreply@onlinestarlet.com', 'to' => $email, 'subject' => 'You Have Just Subscribed', 'text' => 'Thanks For Confirming, You are now subscribed' ]); header('Location: ./'); } ``` }