Attempting to send mail has all of a sudden started returning zero response codes.
<?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);
SendGrid\Response Object
(
[statusCode:protected] => 0
[body:protected] =>
[headers:protected] => Array
(
[0] =>
)
)
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?
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.
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.
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
@DvdGiessen it works like a charm! 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 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_
Works for me!! thanks
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 https://github.com/sendgrid/php-http-client/pull/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?
@DvdGiessen thanks, setting up the curl.cainfo option inside php.ini fixed the problem for me :+1:
@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).
Most helpful comment
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.pemfile and configuring it, see here.It would probably be a good idea to add some error detection to
sendgrid/php-http-clienthere so that cURL errors may be catched and an error may be thrown instead of failing silently.