PHP ActiveX Requires Chilkat v11.0.0+
PHP ActiveX
SendGrid: Look up a bounced email address
See more SendGrid Examples
Look up a recipient on the bounce suppression list without changing it. SendGrid returns an array. An empty array means there is no bounce record for this lookup; it does not prove a particular message reached the inbox.
Chilkat PHP ActiveX Downloads
<?php
$success = 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$success = 0;
$http = new COM("Chilkat.Http");
$http->RequireSslCertVerify = 1;
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
$http->AuthToken = 'SENDGRID_API_KEY';
$resp = new COM("Chilkat.HttpResponse");
// SetUrlVar encodes the raw address as a URL component, including the plus sign.
$http->SetUrlVar('address','avery+orders@example.com');
$success = $http->HttpNoBody('GET','https://api.sendgrid.com/v3/suppression/bounces/{$address}',$resp);
if ($success != 1) {
if ($resp->StatusCode == 0) {
print $http->LastErrorText . "\n";
}
else {
print 'HTTP ' . $resp->StatusCode . ': ' . $resp->BodyStr . "\n";
}
exit;
}
if ($resp->StatusCode != 200) {
print 'HTTP ' . $resp->StatusCode . ': ' . $resp->BodyStr . "\n";
exit;
}
$rows = new COM("Chilkat.JsonArray");
$success = $rows->Load($resp->BodyStr);
if ($success != 1) {
print 'Unexpected response: expected JSON.' . "\n";
exit;
}
if ($rows->Size == 0) {
print 'No bounce record for this address.' . "\n";
exit;
}
$row = new COM("Chilkat.JsonObject");
$i = 0;
while (($i < $rows->Size)) {
$rows->ObjectAt2($i,$row);
print $row->stringOf('email') . ': ' . $row->stringOf('status') . ' ' . $row->stringOf('reason') . "\n";
$i = $i + 1;
}
?>