Skip to content

Latest commit

 

History

History
130 lines (86 loc) · 4.63 KB

TROUBLESHOOTING.md

File metadata and controls

130 lines (86 loc) · 4.63 KB

If you have a non-library SendGrid issue, please contact our support team.

If you can't find a solution below, please open an issue.

Table of Contents

Migrating from v2 to v3

In this context, we are referring to the version of the SendGrid API.

Please review our guide on how to migrate from v2 to v3.

Continue Using v2

In this context, we are referring to the version of the SendGrid API.

Here is the last working version with v2 support.

Using composer:

{
  "require": {
    "sendgrid/sendgrid": "~4.0.4"
  }
}

Download packaged zip here.

Testing v3 /mail/send Calls Directly

Here are some cURL examples for common use cases.

Error Messages

Failed requests will always return an error response, including a response code, a message explaining the reason for the error, and a link to any relevant documentation that may help you troubleshoot the problem.

To read the error message returned by SendGrid's API:

try {
    $response = $sendgrid->send($email);
    print $response->statusCode() . "\n"; 
    print_r($response->headers());
    print $response->body() . "\n"; // SendGrid specific errors are found here
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

You may find complete documentation here.

Versions

We follow the MAJOR.MINOR.PATCH versioning scheme as described by SemVer.org. Therefore, we recommend that you always pin (or vendor) the particular version you are working with to your code and never auto-update to the latest version. Especially when there is a MAJOR point release, since that is guaranteed to be a breaking change. Changes are documented in the CHANGELOG and releases section.

Environment Variables and Your SendGrid API Key

All of our examples assume you are using environment variables to hold your SendGrid API key.

If you choose to add your SendGrid API key directly (not recommended):

$apiKey = getenv('SENDGRID_API_KEY');

becomes

$apiKey = 'SENDGRID_API_KEY';

In the first case SENDGRID_API_KEY is in reference to the name of the environment variable, while the second case references the actual SendGrid API Key.

Using the Package Manager

We upload this library to Packagist whenever we make a release. This allows you to use composer for easy installation.

In most cases we recommend you download the latest version of the library, but if you need a different version, please use:

{
  "require": {
    "sendgrid/sendgrid": "~X.X.X"
  }
}

Fixing Error 415

If you're getting the following error while using this library:

Content-Type should be application/json.

It is most likely due to a linebreak in your API key. Passing your key through trim should fix this:

$apiKey = trim($apiKey)

Viewing the Request Body

When debugging or testing, it may be useful to examine the raw request body to compare against the documented format.

You can do this right before you call $response = $sg->send($email); like so:

echo json_encode($email, JSON_PRETTY_PRINT);

Google App Engine installation

Please refer to USE_CASES.md for additional instructions.