Hello,
about 2-3 weeks ago I was implementing SendGrid php api to my client. Back then when I was using:
$response = $client->client->contactdb()->recipients()->post([$request_body]);
I've received:
object(SendGrid\Response)[5]
public '_status_code' => int 201
public '_body' => string '{"error_count":0,"error_indices":[],"new_count":0,"persisted_recipients":["bS5waWV0cmFzekBuZXVyb3N5cy5wbA=="],"unmodified_indices":[0],"updated_count":0}' (length=153)
public '_headers' => string 'HTTP/1.1 201 CREATED
Server: nginx
...
...
this was on version 5.0.9.
Right now in 5.1.1 I receive this:
/home/michal/sendgrid/lib/SendGridHelper.php:76:
object(SendGrid\Response)[5]
protected 'statusCode' => int 201
protected 'body' => boolean false
protected 'headers' =>
array (size=1)
0 => string '1' (length=1)
as you can see the response body is empty. But weird is that I can catch proper body with this code:
ob_start();
$response = $client->client->contactdb()->recipients()->post([$request_body]);
$curl_response = ob_get_contents();
so in my $curl_response variable I would have this:
{"error_count":0,"error_indices":[],"new_count":0,"persisted_recipients":["bS5waWV0cmFzekBuZXVyb3N5cy5wbA=="],"unmodified_indices":[0],"updated_count":0}
Please fix this bug because right now I need to use old version :)
Hi @madara84,
Thanks for letting us know and for providing a detailed issue!
I've added this to our backlog for a fix.
could you give me an estimation time when it will be fixed on master branch ?
Hi @mpietraszneurosys,
It does not look like this would get fixed this quarter unless we get more people voting on this issue or if someone submits a pull request.
@mpietraszneurosys
@mpietraszneurosys
Quick Fix:
Edit sendgrid's Client.php and add the following lines :
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
After the following line:
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
in makeRequest function.
I encountered the same problem. @vsmori 's solution works.
Same issue here, @vsmori 's solution worked as well. Please address.
Thanks for sharing your solution @vsmori. Please fill out this form so we can send you some swag :)
@haibo3318, @cballenar,
Thanks for your votes, I've added them to our backlog.
@thinkingserious , please send again the form.
@vsmori, sorry about that, here it is.
I am also seeing this issue. The above worked for me.
Stop turning off CURLOPT_SSL_VERIFYPEER and fix your PHP config
Disabling verification of the certificate allows bad guys to man-in-the-middle the communication without you knowing it. Disabling verification makes the communication insecure. Just having encryption on a transfer is not enough as you cannot be sure that you are communicating with the correct end-point.
References :
https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html
Remove this setting by default and let unsecure users to turn it off with a configuration.
if ($this->disableSSLVerifyPeer) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
}
Thanks for the feedback @ylupien,
I have added your vote.
For clarity, is this a new BUG introduced in 5.1.1 (I never had an issue prior to this)?
If @vsmori solution has a security flaw, what is the recommended approach, revert to a previous version?
Many thanks
@birdy247,
I suggest you use the previous version until we have time to investigate deeper.
Isn't this all related to #328, #333 and the fact that in some PHP setups (particularly Windows), the cURL PHP module is missing CA certificates so by default it will reject all SSL certificates as unverifiable?
Also, what @ylupien said. You definitely don't want to disable peer verification.
Is there any update on this?
Hi @birdy247,
It's still fairly low on our backlog. The only thing that would give this issue a significant bump in priority would be a PR.
With Best Regards,
Elmer
Hello Everyone,
Please follow progress at this thread: https://github.com/sendgrid/sendgrid-php/issues/321
Hi ,
I'm geting this response on the clinet server when run the code. But on local its working fine and laos show log in activity on send grid. But when put code on client server and test it give this response and email goes. But not showing in activity log
Thanks To All
SendGrid\Response Object
(
[statusCode:protected] => 0
[body:protected] =>
[headers:protected] => Array
(
[0] =>
)
)
@siwach22,
Please review this this thread: https://github.com/sendgrid/sendgrid-php/issues/348
Thanks!
I was facing the same problem and spent a couple of hours figuring out. I set the CURLOPT_SSL_VERIFYPEER in Client.php of sendGrid API.
_I have set CURLOPT_SSL_VERIFYPEER => to false instead of true_

I hope this may help others to a void getting the 0 status code.
Most helpful comment
@mpietraszneurosys
@mpietraszneurosys
Quick Fix:
Edit sendgrid's Client.php and add the following lines :
After the following line:
in makeRequest function.