M_R_K
M_R_K

Reputation: 6360

How to read API response when a mail is successfully queued using Mailgun's official PHP SDK?

I am super confused how to read API response when a mail is successfully queued using Mailgun's official PHP SDK (2.8).

// First, instantiate the SDK with your API credentials
$mg = Mailgun::create('key-example'); // For US servers
$mg = Mailgun::create('key-example', 'https://api.eu.mailgun.net'); // For EU servers

// Now, compose and send your message.
// $mg->messages()->send($domain, $params);
$response = $mg->messages()->send('example.com', [
  'from'    => '[email protected]',
  'to'      => '[email protected]',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);

var_dump($response);
//Var dump results

object(Mailgun\Model\Message\SendResponse)#130 (2) {
  ["id":"Mailgun\Model\Message\SendResponse":private]=>
  string(52) "<[email protected]>"
  ["message":"Mailgun\Model\Message\SendResponse":private]=>
  string(18) "Queued. Thank you."
}

$response is a private object and I cannot read "Queued. Thank you." inside of it. I cannot find any relevant functions to do that in the documentation. Am I missing something here ?

Upvotes: 3

Views: 1230

Answers (1)

Kenneth Billones
Kenneth Billones

Reputation: 313

You can get the following data by this

For the ID:$response->getId()

For the message: $response->getMessage()

Cheers

Upvotes: 7

Related Questions