I'm using Mailjet to add subscriber for newsletter. How to check email has been subscribed or not.
I'm using the following method before but doesn't check or return email has been subscribe or not just update it and return response success.
Here's my code:
$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.');
}
Hope there's solution for it and thanks a ton.
The response contains the $response->success
details as well, you can review them easily with:
$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) {
}
}
}
If you need to check afterward, you can make a call with Resources::$ContactGetcontactslists
$response = $mailjet->get(Resources::$ContactGetcontactslists, [
'id' => 'email or id'
]);
var_dump($response->getData());
var_dump($response->success());
var_dump($response->getStatus());
Which will return
array(1) {
[0]=>
array(3) {
["IsActive"]=>
bool(true)
["IsUnsub"]=>
bool(false)
["ListID"]=>
int(1)
}
}
bool(true)
int(200)