Sendgrid-php: Sendgrid v3 with no Client

Created on 14 Dec 2017  路  3Comments  路  Source: sendgrid/sendgrid-php

Issue Summary

I have tried to use Sendgrid V3. I do not use Composer. I tried to follow the proposed resolution to issue 412 to no avail.

I also find the statement that the doc needs to be updated for non client but there is no time, a but lame and discouraging.

Do I have to use V3?
Will V2 be abandoned any time soon?
Can you give simple step example of using V3 without a client?

If the answers are Y,Y,N i'm going to have to look for another alternative to Sendgrid.
Rather that having me reproduce the steps that cause the errors, why dont you create and share the steps that dont.

help wanted question

All 3 comments

  1. You don't have to use V3. However, all new functionality will be added to v3.
  2. V2 is safe, we have no plans to make that go away.
  3. You don't need to use Composer, here is the information on how to get the non-composer package of this library.

Hi @morazain,

Here are the steps I used to install and run SendGrid v3:

mkdir test
cd test
wget http://dx.sendgrid.com/downloads/sendgrid-php/sendgrid-php-latest.zip (link retrieved [here](https://github.com/sendgrid/sendgrid-php#alternative-install-package-from-zip))
unzip sendgrid-php-latest.zip

In my editor, I created a file test.php with the following contents (code sample obtained from here):

<?php
require("./sendgrid-php/sendgrid-php.php");

$from = new SendGrid\Email("DX Team", "[email protected]");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Elmer Thomas", "[email protected]");
$content = new SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP");
$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();

Note that I already have SENDGRID_API_KEY defined as an environment variable

php test.php

Email received with a status code of 202.

I hope this helps.

With Best Regards,

Elmer

Thank you Elmer.

I have finally succeeded in sending emails in V3. I guess the SDK i had downloaded was not up to snuff.
The latest, you suggested, worked perfectly.

My next move was to modify it to send an email to multiple recipients, personalized by recipients.
Now that I have the right SDK i was able to create that without an issue:)

I have added a comment to #318 with the example below which I hope others find useful.

test3m.zip

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FilipLukac picture FilipLukac  路  4Comments

izhukovich picture izhukovich  路  4Comments

bjornmann picture bjornmann  路  3Comments

jverlee picture jverlee  路  4Comments

micahwalter picture micahwalter  路  3Comments