I'm trying to execute this test script and it is always returning a zero error code status. No log, no more information about how to trace it. What can I do?
<?php
// If you are using Composer
require "<MY_PATH>/vendor/autoload.php";
$from = new SendGrid\Email(null, "<MY_FROM>@<EMAIL>");
$subject = "Hello World from the SendGrid PHP Library!";
$to = new SendGrid\Email(null, "<MY_TO>@<EMAIL>");
$content = new SendGrid\Content("text/plain", "Hello, Email!");
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$sg = new \SendGrid("<MY_API_KEY>");
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode() . PHP_EOL;
echo $response->body() . PHP_EOL;
echo implode(', ', $response->headers()) . PHP_EOL;
Output screenshot

Hello @davidromani,
I just tried to duplicate your issue (the file is in the root directory):
<?php
require "vendor/autoload.php";
$from = new SendGrid\Email(null, "[email protected]");
$subject = "Hello World from the SendGrid PHP Library!";
$to = new SendGrid\Email(null, "[email protected]");
$content = new SendGrid\Content("text/plain", "Hello, Email!");
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode() . PHP_EOL;
echo $response->body() . PHP_EOL;
echo implode(', ', $response->headers()) . PHP_EOL;
And my response was:
202
, X-Frame-Options: DENY3RZOp6TPvS0PXewf-8
I am using PHP 7.0.14 and I also tested with version 5.6.14 with the same result.
Now is working... thanks for you answer. I don't understand why now is working, but thanks again.
Same problem again :-(
@thinkingserious why you don't return more explicit error messages? It's very difficult to understand what's happening...
Hello @davidromani,
I'm not sure what is happening, but it seems you are receiving that status code because our servers did not get your message, see: http://stackoverflow.com/questions/872206/http-status-code-0-what-does-this-mean-in-ms-xmlhttp
We don't actually send a status code 0 back. Here are the status codes we support: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
I hope that helps, thanks!
@thinkingserious do you have any curl command to try the same action (send a test email) at a lower level? I understand that sendgrid-php library relies on php-curl extension, right?
@davidromani,
Here you go: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/curl_examples.html
@thinkingserious I've just tried to execute "Hello, World!" example with my API Key and it works perfectly.
Same machine, same environment and same API key. So maybe, I need to check php-curl extension version, compile config params...?
Hi @davidromani,
That sounds like a solid approach. Please do share what you find. Thanks!
My phpinfo config related with php-curl extension is:

Can anybody test a similar environment?
@thinkingserious I've testet with another machine (Ubuntu + PHP 5.6) and it works perfect. Maybe is a problem related with this PHP 7.0 distro https://php-osx.liip.ch and the default complied extensions..
Do you want to close this issue and I will open another one more specific?
Hi @davidromani,
I think not deleting this thread would be sufficient, so that those who search for status code 0 issue will find it.
Thank you for taking the time to report your findings!
Same issue here on IIS
Hello @sadranyi,
Have you checked your php.ini to ensure you have php-curl enabled?
With Best Regards,
Elmer
Yes I have
On 2 May 2018 at 17:12, Elmer Thomas notifications@github.com wrote:
Hello @sadranyi https://github.com/sadranyi,
Have you checked your php.ini to ensure you have php-curl enabled?
With Best Regards,
Elmer
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-php/issues/348#issuecomment-386158956,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAid3DsnIaSNa83-bbL7OMLpjfEAPhTcks5tuktxgaJpZM4LpqJ_
.
Hi @sadranyi
Are you running a Windows PHP distribution? If so read this article on how to fix it. Have a nice evening!
yes am running a windows distro in IIS.
Will look at the link
On 3 May 2018 at 15:02, Martijn Melchers notifications@github.com wrote:
Hi @sadranyi https://github.com/sadranyi
Are you running a Windows PHP distribution? If so read this
https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
article on how to fix it. Have a nice evening!—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-php/issues/348#issuecomment-386450869,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAid3J3PyPH9yWqKzogeGZPflCvi5NT0ks5tu359gaJpZM4LpqJ_
.
It works fine if i deploy in Xampp, but returns 0 when i run the same code
in IIS
On 3 May 2018 at 15:17, Samuel Adranyi sadranyi@gmail.com wrote:
yes am running a windows distro in IIS.
Will look at the linkOn 3 May 2018 at 15:02, Martijn Melchers notifications@github.com wrote:
Hi @sadranyi https://github.com/sadranyi
Are you running a Windows PHP distribution? If so read this
https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/
article on how to fix it. Have a nice evening!—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-php/issues/348#issuecomment-386450869,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAid3J3PyPH9yWqKzogeGZPflCvi5NT0ks5tu359gaJpZM4LpqJ_
.
@sadranyi,
Have you tried the steps in the link provided by @martijnmelchers?
Hope this will help: https://github.com/sendgrid/php-http-client/pull/99
That's awesome @alextech, thanks!
Had the same issue and just needed to download the latest cacert.pem file and making sure the php.ini file referenced it properly.
I already sent emaill successfully yesterday. But today it responsed that:
object(SendGrid\Response)#17 (3) {
["statusCode":protected]=>
int(0)
["body":protected]=>
string(0) ""
["headers":protected]=>
array(1) {
[0]=>
string(0) ""
}
}
Can anyone help me ?
Hello @congnghiakhiem,
I would audit your system to find out what changed from the day it stopped working. Perhaps an upgrade, for example?
Thank @thinkingserious
I have changed to use python, and sent +20k mails successfully. Therefore, I won't use php again.
Same problem here too.
public function send($fromName, $fromEmail, $subject, $toName, $toEmail, $txtContent, $htmlContent) {
$email = new \SendGrid\Mail\Mail();
$email->setFrom($fromEmail, $fromName);
$email->setSubject($subject);
$email->addTo($toEmail, $toName);
$email->addContent("text/plain", $txtContent);
$email->addContent("text/html", $htmlContent);
$sendgrid = new \SendGrid($this->container->settings["sendgrid"]["token"]);
$this->container->logger->info("Sending email to: {$toEmail} ...");
$response = $sendgrid->send($email);
$this->container->logger->info(json_encode($response));
return $response;
}
$response is empty. All data passed into the function I created is correct. Been stuck on this for days now.
hello guy!
How to get status when sendmail in laravel?
@martijnmelchers link did it for me
Most helpful comment
Hi @sadranyi
Are you running a Windows PHP distribution? If so read this article on how to fix it. Have a nice evening!