sendgrid / sendgrid-php

The Official Twilio SendGrid PHP API Library
https://sendgrid.com
MIT License
1.49k stars 625 forks source link

502 errors trying to send email #827

Closed justageek closed 4 years ago

justageek commented 5 years ago

Issue Summary

We have recently started getting 502 errors in code that had been working to send emails, we have just upgrade to version 7.x of the libraries, but even that code tested fine.

Steps to Reproduce

  1. We build a Mail object that has html content for the body
  2. We execute a post to mail/send with that Mail object as the argument. ` SendGrid\Response Object ( [statusCode:protected] => 502 [body:protected] =>

    SendGrid - 502 Bad Gateway

    502

    Ngnix - Bad Gateway

    [headers:protected] => Array ( [0] => HTTP/1.1 100 Continue [1] => [2] => HTTP/1.1 502 Bad Gateway [3] => Server: nginx [4] => Date: Thu, 11 Apr 2019 22:42:32 GMT [5] => Content-Type: text/html [6] => Content-Length: 6023 [7] => Connection: keep-alive [8] => ETag: "5c65cb07-1787" [9] => [10] => ) ) `

    Technical details:

thinkingserious commented 5 years ago

Hello @justageek,

That error means your server is having trouble connecting with our server. You might want to reach out to our support team or your server provider to help debug that issue.

With Best Regards,

Elmer

justageek commented 5 years ago

Thanks, we found so far that because we are using a queue system provided by the Drupal CMS to send multiple messages in batch, we are going to try some modifications to how we instantiate the SendGrid library client and cache it statically, we found that the very first message always works perfectly, and then the rest do not, so we might be grasping at straws, but sending one-off messages works perfectly, it has something to do with queueing up a batch and processing then in a single cron run that appears to be part of the issue.

justageek commented 5 years ago

We are also seeing the following error

Undefined variable: plain_content Mail.php:1133

I don't know if that would be causing issues with sending when building the message content.

justageek commented 5 years ago

Is there an easy way to debug the curl request the library uses to contact SendGrid?

thinkingserious commented 5 years ago

I would suggest taking a look at the request body and comment out the sending function until resolution.

edtsz commented 5 years ago

I'm having the same problem. Today I got 35 occurrences.. :disappointed:

Response:

    [headers:protected] => Array
        (
            [0] => HTTP/1.1 502 Bad Gateway
            [1] => Server: nginx
            [2] => Date: Thu, 18 Jul 2019 18:20:36 GMT
            [3] => Content-Type: text/html
            [4] => Content-Length: 6023
            [5] => Connection: keep-alive
            [6] => ETag: "5c6599f9-1787"
            [7] => 
            [8] => 
        )

My environment:

Linux CentOS 3.10.0-693.17.1.el7.x86_64

PHP 7.1.26 (cli) (built: Jan 12 2019 09:59:05) ( NTS )
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

sendgrid/php-http-client        3.9.6
sendgrid/sendgrid               7.3.0
SamMousa commented 5 years ago

This issue is actually fixed here: https://github.com/sendgrid/sendgrid-php/commit/b0a3721d9e42121140b3ac4ecb5263827740a3ec

But the Sendgrid package(s) have been improperly tagged thus missing commits.

thinkingserious commented 4 years ago

Hello everyone,

It looks to me like this issue is now fixed in the latest version of this helper library. Thanks!

With best regards,

Elmer