CkPhp Requires Chilkat v11.0.0+
CkPhp
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 CkPhp Downloads
<?php
include("chilkat.php");
$success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$success = false;
$http = new CkHttp();
$http->put_RequireSslCertVerify(true);
// Supply your API key from protected configuration; AuthToken adds the Bearer prefix.
$http->put_AuthToken('SENDGRID_API_KEY');
$resp = new CkHttpResponse();
// 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 != true) {
if ($resp->get_StatusCode() == 0) {
print $http->lastErrorText() . "\n";
}
else {
print 'HTTP ' . $resp->get_StatusCode() . ': ' . $resp->bodyStr() . "\n";
}
exit;
}
if ($resp->get_StatusCode() != 200) {
print 'HTTP ' . $resp->get_StatusCode() . ': ' . $resp->bodyStr() . "\n";
exit;
}
$rows = new CkJsonArray();
$success = $rows->Load($resp->bodyStr());
if ($success != true) {
print 'Unexpected response: expected JSON.' . "\n";
exit;
}
if ($rows->get_Size() == 0) {
print 'No bounce record for this address.' . "\n";
exit;
}
$row = new CkJsonObject();
$i = 0;
while (($i < $rows->get_Size())) {
$rows->ObjectAt2($i,$row);
print $row->stringOf('email') . ': ' . $row->stringOf('status') . ' ' . $row->stringOf('reason') . "\n";
$i = $i + 1;
}
?>