SendGrid

FREEMIUM
Verified
Official
By sendgrid | Updated 23 days ago | Email
Popularity

9.6 / 10

Latency

286ms

Service Level

100%

Back to All Discussions

My emails are successfully sending but the response is always an empty string variable.

avatar
mikhaelangelo
a year ago

i’m using PHP and CURL to send an email via rapidpro-sendgrid API and everything is done well but the response getted by the curl_exec() are a just blank and empty string (with double quotes).

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_ENCODING, "UTF-8");
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $messageField);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("accept: application/json","content-type: application/json","x-rapidapi-host: rapidprod-sendgrid-v1.p.rapidapi.com","x-rapidapi-key: *******"));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
     echo "cURL Error #:" . $err;
} else {
     echo $response;
}
avatar
alexwalling commented a year ago

That’s to be expected! Any time an email is successfully send the request will simply respond with an empty 202 response.

avatar
mikhaelangelo commented a year ago

lol, really? so i was all this time thinking that was something wrong… oh fuck hahahaha. So, in this case, we can say: if th response get anything than an empty string, thats mean there something got wrong? I mean… i can validate the send by doing something like:

if($response === "") {
echo "Success";
} else {
echo "Email not sent";
}

Is it safe to trust it? I really didn’t found anything in the docs that explain such a thing.

Join in the discussion - add comment below:

Login / Signup to post new comments
Rating: 4.8 - Votes: 5