Skip to content
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

SendGrid Bad Gateway #31

Open
JASchilz opened this issue Jan 23, 2018 · 1 comment
Open

SendGrid Bad Gateway #31

JASchilz opened this issue Jan 23, 2018 · 1 comment

Comments

@JASchilz
Copy link

I'm getting a bad gateway error when sending an e-mail with SendGrid. I've confirmed that:

  1. The error occurs with the example code provided in README.md
  2. The error doesn't occur when using the bare SendGrid library.
  3. The error occurs on multiple machines.

I can reproduce as follows:

$ composer require sendgrid/sendgrid
$ composer require omnimail/omnimail
/* test1.php */
<?php
require_once (__DIR__ . '/vendor/autoload.php');

use Omnimail\Email;
use Omnimail\Sendgrid;

$mailer = new Sendgrid(MY_REAL_LIFE_SG_KEY);

$email = (new Email())
    ->addTo('example@email.com')
    ->setFrom('example@email.com')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);
/* test2.php */
<?php
require_once (__DIR__ . '/vendor/autoload.php');

$from = new SendGrid\Email("Example User", "test@example.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Example User", "test@example.com");
$content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
$mail = new SendGrid\Mail($from, $subject, $to, $content);

$sg = new \SendGrid(MY_REAL_LIFE_SG_KEY);

$response = $sg->client->mail()->send()->post($mail);
echo $response->statusCode();
print_r($response->headers());
echo $response->body();
$ php test1.php
PHP Fatal error:  Uncaught exception 'Omnimail\Exception\InvalidRequestException' in C:\Users\jschilz\test\vendor\omnimail\omnimail\src\Sendgri
d.php:137
Stack trace:
#0 C:\Users\jschilz\test\test1.php(15): Omnimail\Sendgrid->send(Object(Omnimail\Email))
#1 {main}
  thrown in C:\Users\jschilz\test\vendor\omnimail\omnimail\src\Sendgrid.php on line 137

Fatal error: Uncaught exception 'Omnimail\Exception\InvalidRequestException' in C:\Users\jschilz\test\vendor\omnimail\omnimail\src\Sendgrid.php
 on line 137

Omnimail\Exception\InvalidRequestException:  in C:\Users\jschilz\test\vendor\omnimail\omnimail\src\Sendgrid.php on line 137

Call Stack:
    0.0002     124920   1. {main}() C:\Users\jschilz\test\test1.php:0
    0.0056     425304   2. Omnimail\Sendgrid->send() C:\Users\jschilz\test\test1.php:15

I put some debugging statements inside SendGrid.php to determine that SendGrid is returning a 502 Bad Gateway response.

$ php test2.php
202Array
(
    [0] => HTTP/1.1 202 Accepted
    [1] => Server: nginx
    [2] => Date: Tue, 23 Jan 2018 00:26:40 GMT
    [3] => Content-Type: text/plain; charset=utf-8
    [4] => Content-Length: 0
    [5] => Connection: keep-alive
    [6] => X-Message-Id: AFEhnCqnT46tLy-1FAdm-A
    [7] => Access-Control-Allow-Origin: https://sendgrid.api-docs.io
    [8] => Access-Control-Allow-Methods: POST
    [9] => Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl
    [10] => Access-Control-Max-Age: 600
    [11] => X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html
    [12] =>
    [13] =>
)

I can work to trouble shoot this tomorrow, but I thought I'd post the issue tonight incase the solution is obvious to you. (:

@gabrielbull
Copy link
Collaborator

Ah no, it's not obvious straight away. They may have changed the way their library works and it's broken ours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants