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

标签 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);
//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."
}

$response 是私有(private)对象,我无法读取“已排队。谢谢。”在里面。我在文档中找不到任何相关功能来执行此操作。我在这里遗漏了什么吗?

最佳答案

通过这个可以得到如下数据

对于ID:$response->getId()

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

干杯

关于php - 如何使用 Mailgun 的官方 PHP SDK 在邮件成功排队时读取 API 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57541163/

相关文章:

php - 列出字符类的成员

ruby-on-rails - 用于 Ruby on Rails 的 Sendgrid API

mailgun - 递送问题 - Hotmail 和 Yahoo

php - php 中的 echo 没有显示回 HTML 页面

php - Twitter OAuth (PHP) : Need good, 入门基本示例

php - 操作系统错误: [Errno 22] Python PHP Problem

tags - 如何在使用 Mailgun 的 SMTP 选项时控制跟踪选项和标签(即不使用他们的 API)

dns - 设置Google Domains DNS以与Mailgun MX记录一起使用

php - 在 Laravel 5 中为 Mailgun 添加 Guzzle

php - 尝试使用 PDO 从数据库动态加载数据