Mailjet如何查看电子邮件已订阅或未订阅

时间:2016-02-11 03:46:09

标签: php api mailjet

我正在使用Mailjet为简报添加订阅者。 如何查看电子邮件已订阅或未订阅。

我以前使用过以下方法,但没有订阅或退回电子邮件已订阅或不更新并返回响应成功。

这是我的代码:


$mj            = new \Mailjet\Client(MJ_APIKEY_PUBLIC, MJ_APIKEY_PRIVATE);
// CREATE CONTACT AND SUBSCRIBE AT ONCE
// Adding User into Mailjet Contact as Subscriber for Newsletter
$body          = [
    'Email' => $POST['email'],
    'Name' => $POST['name'],
    'Action' => "addnoforce",
];
$contactlistID = 3;
$response      = $mj->post(\Mailjet\Resources::$ContactslistManagecontact, ['id' => $contactlistID, 'body' => $body]);

// Read the response
if ($response->success()) {
    $feedback = array('type' => 'success', 'msg' => 'Your email has been registered succesfully.');
}

希望有解决方案并感谢他们。

1 个答案:

答案 0 :(得分:1)

响应还包含$response->success详细信息,您可以使用以下方法轻松查看:

$response->getData()

array(1) {
  [0]=>
    array(5) {
      ["ContactID"]=>
        int(1682906939)
      ["Email"]=>
        string(14) "gbadi@test.com"
      ["Action"]=>
        string(10) "addnoforce"
      ["Name"]=>
        string(13) "Test"
      ["Properties"]=>
        array(0) {
        }
     }
   }

如果您之后需要查看,可以使用Resources::$ContactGetcontactslists

拨打电话
$response = $mailjet->get(Resources::$ContactGetcontactslists, [
  'id' => 'email or id'
]);

var_dump($response->getData());
var_dump($response->success());
var_dump($response->getStatus());

将返回

array(1) {
  [0]=>
  array(3) {
    ["IsActive"]=>
    bool(true)
    ["IsUnsub"]=>
    bool(false)
    ["ListID"]=>
    int(1)
  }
}
bool(true)
int(200)