使用 Mailgun 的官方 PHP SDK 成功排队邮件时如何读取 API 响应?

M_R*_*R_K 3 php mailgun

当使用 Mailgun 的官方 PHP SDK (2.8) 成功排队邮件时,我非常困惑如何读取 API 响应。

// 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'    => 'bob@example.com',
  'to'      => 'sally@example.com',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);

var_dump($response);
Run Code Online (Sandbox Code Playgroud)
//Var dump results

object(Mailgun\Model\Message\SendResponse)#130 (2) {
  ["id":"Mailgun\Model\Message\SendResponse":private]=>
  string(52) "<201949588013742.1.5234966234A248269@mydomain.com>"
  ["message":"Mailgun\Model\Message\SendResponse":private]=>
  string(18) "Queued. Thank you."
}
Run Code Online (Sandbox Code Playgroud)

$response 是一个私有对象,我无法读取“已排队。谢谢。” 在它里面。我在文档中找不到任何相关函数来执行此操作。我在这里错过了什么吗?

小智 7

通过此可以得到以下数据

对于身份证:$response->getId()

对于消息:$response->getMessage()

干杯