When attempting to call $sg->client->mail()->send()->post($mail); per the Quick Start in README.md, I'm receiving the error "Permission denied, wrong credentials". I have verified that the API key I am using is correct and also have tried creating new API keys.
Where it gets interesting is that if I downgrade the sendgrid-php library to version 5.0.0, I'm able to successfully send an email.
Any thoughts here would be helpful! Thanks
Run the code from the Quick Start in README.md.
Looks like downstream dependency is properly broken — 2 last patches have introduced different regressions, see https://github.com/sendgrid/php-http-client/commit/46dcffa8b1c3ff56acbb78124d9e1e37d70d8c30.
Workaround is to pin "sendgrid/php-http-client": "3.9.0"
@thedotedge makes sense. Thanks!
Correction: it's actually 3.8.0 that works, all subsequent versions are broken. I wonder if it even makes sense to depend on "sendgrid/php-http-client": "~3.7" in sendgrid/sendgrid-php if downstream is so unstable.
In fact, even API is broken after sendgrid/php-http-client update: sample code sendgrid()->client->mail()->send()->post($mail); that is supposed to return response object silently start returning itself 😞
@thedotedge Pinning to 3.9.0 introduced a notice (seen below), but 3.8.0 seems to do the trick. Thanks!
Notice: Object of class SendGrid\Client could not be converted to int in /Users/frank/<removed>/vendor/sendgrid/php-http-client/lib/Client.php on line 269
@thedotedge @fterrag
Please try php-http-client 3.9.2, that version should be good to go. Thanks!
@thinkingserious does it work for you? For me every request was returning 401.
@thinkingserious I also receive a 401 when using php-http-client 3.9.2. It appears the problem might lie in Client.php around lines 192-196:
if (isset($headers)) {
$headers = array_merge($this->headers, $headers);
} else {
$headers = []; // If $headers is null, $this->headers never gets used in the request.
}
Should probably be changed to:
if (isset($headers)) {
$headers = array_merge($this->headers, $headers);
} else {
$headers = $this->headers; // If $headers is null, $this->headers will still be used in the request.
}
When this change is made, I'm able to successfully send email. I'm not too familiar with the library, so this might not be the best/correct place to solve the issue.
@thedotedge,
It was working for me when using php-http-client directly. I believe @fterrag found the fix though. When we set $headers = [] we are overwriting the values coming from sendgrid-php. I'm fixing now with 3.9.3.
With Best Regards,
Elmer
Thanks again to everyone on this thread for helping get a fix pushed out quickly.
I have verified that this bug is fixed using 3.9.3 in sendgrid-php.
Thanks again!
Related to #585.
Most helpful comment
@thinkingserious I also receive a 401 when using php-http-client 3.9.2. It appears the problem might lie in Client.php around lines 192-196:
Should probably be changed to:
When this change is made, I'm able to successfully send email. I'm not too familiar with the library, so this might not be the best/correct place to solve the issue.