Skip to content

Response returning zero status code #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
garyrutland opened this issue Nov 14, 2016 · 10 comments
Closed

Response returning zero status code #328

garyrutland opened this issue Nov 14, 2016 · 10 comments
Labels
type: question question directed at the library

Comments

@garyrutland
Copy link

Issue Summary

Attempting to send mail has all of a sudden started returning zero response codes.

Steps to Reproduce

<?php

// get sendgrid
$sendgrid = new \SendGrid('MY_KEY');

// create sender and recipient
$from = new SendGrid\Email('App name', '[email protected]');
$to = new SendGrid\Email('Users name', '[email protected]');

// create subject and content
$subject = 'Email title';
$content = new SendGrid\Content('text/plain', 'Test content');

// create email
$mail = new SendGrid\Mail($from, $subject, $to, $content);

// send email
$result = $sendgrid->client->mail()->send()->post($mail);

Technical details:

SendGrid\Response Object
(
    [statusCode:protected] => 0
    [body:protected] => 
    [headers:protected] => Array
        (
            [0] => 
        )
)
  • sendgrid-php Version: master (latest commit: aa09fb8)
  • PHP Version: 7.0.11
@thinkingserious thinkingserious added the type: question question directed at the library label Nov 15, 2016
@thinkingserious
Copy link
Contributor

Hello @garyrutland,

Unfortunately, I am unable to reproduce. Here is what I used:

<?php
// If you are using Composer
require 'vendor/autoload.php';

// get sendgrid
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));

// create sender and recipient
$from = new SendGrid\Email('App name', '[email protected]');
$to = new SendGrid\Email('Users name', '[email protected]');

// create subject and content
$subject = 'Email title';
$content = new SendGrid\Content('text/plain', 'Test content');

// create email
$mail = new SendGrid\Mail($from, $subject, $to, $content);

// send email
$result = $sendgrid->client->mail()->send()->post($mail);

Which returned

SendGrid\Response Object
(
    [statusCode:protected] => 202
    [body:protected] =>
    [headers:protected] => Array
        (
            [0] => 1
        )
)

Does you email get delivered?

@DvdGiessen
Copy link

DvdGiessen commented Nov 18, 2016

I just came across this issue as well on a freshly installed Windows development machine, and for me it turned out to be the cURL PHP module missing CA certificates and thus refusing to connect to the SendGrid API. The issue can be resolved by downloading the required cacerts.pem file and configuring it, see here.

It would probably be a good idea to add some error detection to sendgrid/php-http-client here so that cURL errors may be catched and an error may be thrown instead of failing silently.

@garyrutland
Copy link
Author

Sorry, for the late response but haven't had a chance to carry one working on this.
I have just tried again with the same code as before and am now getting 202 responses and emails are being sent.

@alyak46141414
Copy link

I found that zero may return with curl error
SSL certificate problem: unable to get local issuer certificate

so need setup certificate for php to use this service , no option to disable

@VictorHaine
Copy link

@DvdGiessen it works like a charm! thanks!

@sulemantech
Copy link

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

image

@apineda7
Copy link

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

image

Works for me!! thanks

@DvdGiessen
Copy link

Since I'm still subscibed to this issue, I noticed the replies by @shahrpt and @apineda7 about how setting CURLOPT_SSL_VERIFYPEER to false also makes the error message go away. THIS IS NOT RECOMMENDED!

By doing so you're basically disabling an import part of your security, setting yourself up for a man-in-the-middle attack on your connections to SendGrid and potentially allowing an attacker to read, modify or do whatever else they want with the e-mails you try to send through SendGrid.

Instead, as mentioned in my previous comment, fix the actual problem and you won't have to disable your security. See https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/.

@thinkingserious Any chance we could prioritize getting sendgrid/php-http-client#99 merged which would clear up the error message and next perhaps add a line about this specific issue in the documentation to prevent users from potentially shooting themselves in the foot by disabling CURLOPT_SSL_VERIFYPEER?

@daniilkarpov
Copy link

@DvdGiessen thanks, setting up the curl.cainfo option inside php.ini fixed the problem for me 👍

@Ludplay
Copy link

Ludplay commented Nov 26, 2019

@DvdGiessen I got curious. It would be good to know why this happens just in windows machines (if that's the case, as it seems to be).
As far as I know, the Client.php and the php.ini are the same (about curl CA stuff).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

9 participants