From 7299d3d924a22fe6dc9e3e5f52266dab47d28ad1 Mon Sep 17 00:00:00 2001 From: Alexander Kamp Date: Thu, 6 Aug 2020 22:57:16 +0200 Subject: [PATCH] docs: Reduce excessive comments in code examples (#984) * PHP CS Fixer fixes * Docs: Import classes instead of namespace\class * Line length reductions * Prece(n)dence typos * Remove PHP tailing '?>' tags * Examples pending for migration: senderauthentication, contactdb --- README.md | 49 +- USAGE.md | 11 +- USE_CASES.md | 458 +++++++++--------- examples/accesssettings/accesssettings.php | 11 +- examples/alerts/alerts.php | 11 +- examples/apikeys/apikeys.php | 27 +- examples/asm/asm.php | 51 +- examples/browsers/browsers.php | 7 +- examples/campaigns/campaigns.php | 59 ++- examples/categories/categories.php | 13 +- examples/clients/clients.php | 11 +- examples/contactdb/contactdb.php | 81 ++-- examples/devices/devices.php | 10 +- examples/geo/geo.php | 7 +- examples/helpers/contacts/recipients.php | 23 +- examples/helpers/mail/example.php | 8 +- examples/helpers/stats/example.php | 8 +- examples/ips/ips.php | 7 +- examples/mail/mail.php | 141 +++--- .../mailboxproviders/mailboxproviders.php | 7 +- examples/mailsettings/mailsettings.php | 31 +- examples/partnersettings/partnersettings.php | 11 +- examples/scopes/scopes.php | 9 +- .../senderauthentication.php | 31 +- examples/senders/senders.php | 47 +- examples/stats/stats.php | 7 +- examples/subusers/subusers.php | 19 +- examples/suppression/suppression.php | 23 +- examples/templates/templates.php | 25 +- .../trackingsettings/trackingsettings.php | 28 +- examples/user/user.php | 51 +- 31 files changed, 620 insertions(+), 662 deletions(-) diff --git a/README.md b/README.md index be88344e8..85b0f0f18 100644 --- a/README.md +++ b/README.md @@ -74,37 +74,38 @@ Add Twilio SendGrid to your `composer.json` file. If you are not using [Composer } ``` -#### Alternative: Install package from zip +### Alternative: Install package from zip If you are not using Composer, simply download and install the **[latest packaged release of the library as a zip](https://github.com/sendgrid/sendgrid-php/releases/download/7.8.1/sendgrid-php.zip)**. [**⬇︎ Download Packaged Library ⬇︎**](https://github.com/sendgrid/sendgrid-php/releases/download/7.8.1/sendgrid-php.zip) -Previous versions of the library can be found in the [version index](https://sendgrid-open-source.s3.amazonaws.com/index.html) or downloaded directly from [GitHub](https://github.com/sendgrid/sendgrid-php/releases). +Previous versions of the library can be downloaded directly from [GitHub](https://github.com/sendgrid/sendgrid-php/releases). ## Dependencies - The Twilio SendGrid Service, starting at the [free level](https://sendgrid.com/free?source=sendgrid-php) -- The dependency free [php-http-client](https://github.com/sendgrid/php-http-client) +- The dependency-free [php-http-client](https://github.com/sendgrid/php-http-client) # Quick Start +Include the proper lines from below at the top of each example based on your installation method: + +```php + with the path to the sendgrid-php.php file +// require_once '/sendgrid-php.php'; +``` + ## Hello Email The following is the minimum needed code to send an email. You may find more examples in our USE_CASES file: ```php -/sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - $email = new \SendGrid\Mail\Mail(); $email->setFrom("test@example.com", "Example User"); $email->setSubject("Sending with Twilio SendGrid is Fun"); @@ -129,17 +130,6 @@ The `SendGrid\Mail` constructor creates a [personalization object](https://sendg ## General v3 Web API Usage (With Fluent Interface) ```php -/sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); @@ -156,17 +146,6 @@ try { ## General v3 Web API Usage (Without Fluent Interface) ```php -/sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); diff --git a/USAGE.md b/USAGE.md index c284e721e..41c40abf0 100644 --- a/USAGE.md +++ b/USAGE.md @@ -3,14 +3,9 @@ This documentation is based on our [OAI specification](https://github.com/sendgr # INITIALIZATION ```php -require 'vendor/autoload.php'; // If you're using Composer (recommended) -// Comment out the above line if not using Composer -// require("/sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases +/sendgrid-php.php'; $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); diff --git a/USE_CASES.md b/USE_CASES.md index 4306ea0e8..425892546 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -25,16 +25,12 @@ Here is an example of attaching a text file to your email, assuming that text fi ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$email = new \SendGrid\Mail\Mail(); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\Mail; + +$email = new Mail(); $email->setFrom("test@example.com", "Example User"); $email->setSubject("Sending with Twilio SendGrid is Fun"); $email->addTo("test@example.com", "Example User"); @@ -93,21 +89,20 @@ your app’s JWT scopes. ```php time() + 50 ); -$privateKey = openssl_get_privatekey($boxConfig->boxAppSettings->appAuth->privateKey, $boxConfig->boxAppSettings->appAuth->passphrase); +$privateKey = openssl_get_privatekey( + $boxConfig->boxAppSettings->appAuth->privateKey, + $boxConfig->boxAppSettings->appAuth->passphrase +); $assertion = JWT::encode($claims, $privateKey, 'RS256', null, $header); @@ -238,20 +236,16 @@ if (isset($fileId) && isset($userId)){ ``` -# Kitchen Sink - an example with all settings used +# Kitchen Sink - an example with all settings used ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\Mail; -$email = new \SendGrid\Mail\Mail(); +$email = new Mail(); // For a detailed description of each of these settings, // please see the @@ -434,83 +428,112 @@ OR ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$email = new \SendGrid\Mail\Mail(); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\Asm; +use SendGrid\Mail\Attachment; +use SendGrid\Mail\BatchId; +use SendGrid\Mail\Bcc; +use SendGrid\Mail\BccSettings; +use SendGrid\Mail\BypassListManagement; +use SendGrid\Mail\Category; +use SendGrid\Mail\Cc; +use SendGrid\Mail\ClickTracking; +use SendGrid\Mail\Content; +use SendGrid\Mail\CustomArg; +use SendGrid\Mail\Footer; +use SendGrid\Mail\From; +use SendGrid\Mail\Ganalytics; +use SendGrid\Mail\GroupId; +use SendGrid\Mail\GroupsToDisplay; +use SendGrid\Mail\Header; +use SendGrid\Mail\HtmlContent; +use SendGrid\Mail\IpPoolName; +use SendGrid\Mail\Mail; +use SendGrid\Mail\MailSettings; +use SendGrid\Mail\OpenTracking; +use SendGrid\Mail\PlainTextContent; +use SendGrid\Mail\ReplyTo; +use SendGrid\Mail\SandBoxMode; +use SendGrid\Mail\Section; +use SendGrid\Mail\SendAt; +use SendGrid\Mail\SpamCheck; +use SendGrid\Mail\Subject; +use SendGrid\Mail\SubscriptionTracking; +use SendGrid\Mail\Substitution; +use SendGrid\Mail\TemplateId; +use SendGrid\Mail\To; +use SendGrid\Mail\TrackingSettings; + +$email = new Mail(); // For a detailed description of each of these settings, // please see the // [documentation](https://sendgrid.com/docs/API_Reference/api_v3.html). $email->setSubject( - new \SendGrid\Mail\Subject("Sending with Twilio SendGrid is Fun 2") + new Subject("Sending with Twilio SendGrid is Fun 2") ); -$email->addTo(new \SendGrid\Mail\To("test@example.com", "Example User")); -$email->addTo(new \SendGrid\Mail\To("test+1@example.com", "Example User1")); +$email->addTo(new To("test@example.com", "Example User")); +$email->addTo(new To("test+1@example.com", "Example User1")); $toEmails = [ - new \SendGrid\Mail\To("test+2@example.com", "Example User2"), - new \SendGrid\Mail\To("test+3@example.com", "Example User3") + new To("test+2@example.com", "Example User2"), + new To("test+3@example.com", "Example User3") ]; $email->addTos($toEmails); -$email->addCc(new \SendGrid\Mail\Cc("test+4@example.com", "Example User4")); +$email->addCc(new Cc("test+4@example.com", "Example User4")); $ccEmails = [ - new \SendGrid\Mail\Cc("test+5@example.com", "Example User5"), - new \SendGrid\Mail\Cc("test+6@example.com", "Example User6") + new Cc("test+5@example.com", "Example User5"), + new Cc("test+6@example.com", "Example User6") ]; $email->addCcs($ccEmails); $email->addBcc( - new \SendGrid\Mail\Bcc("test+7@example.com", "Example User7") + new Bcc("test+7@example.com", "Example User7") ); $bccEmails = [ - new \SendGrid\Mail\Bcc("test+8@example.com", "Example User8"), - new \SendGrid\Mail\Bcc("test+9@example.com", "Example User9") + new Bcc("test+8@example.com", "Example User8"), + new Bcc("test+9@example.com", "Example User9") ]; $email->addBccs($bccEmails); -$email->addHeader(new \SendGrid\Mail\Header("X-Test1", "Test1")); -$email->addHeader(new \SendGrid\Mail\Header("X-Test2", "Test2")); +$email->addHeader(new Header("X-Test1", "Test1")); +$email->addHeader(new Header("X-Test2", "Test2")); $headers = [ - new \SendGrid\Mail\Header("X-Test3", "Test3"), - new \SendGrid\Mail\Header("X-Test4", "Test4") + new Header("X-Test3", "Test3"), + new Header("X-Test4", "Test4") ]; $email->addHeaders($headers); $email->addDynamicTemplateData( - new \SendGrid\Mail\Substitution("subject1", "Example Subject 1") + new Substitution("subject1", "Example Subject 1") ); $email->addDynamicTemplateData( - new \SendGrid\Mail\Substitution("name", "Example Name 1") + new Substitution("name", "Example Name 1") ); $email->addDynamicTemplateData( - new \SendGrid\Mail\Substitution("city1", "Denver") + new Substitution("city1", "Denver") ); $substitutions = [ - new \SendGrid\Mail\Substitution("subject2", "Example Subject 2"), - new \SendGrid\Mail\Substitution("name2", "Example Name 2"), - new \SendGrid\Mail\Substitution("city2", "Orange") + new Substitution("subject2", "Example Subject 2"), + new Substitution("name2", "Example Name 2"), + new Substitution("city2", "Orange") ]; $email->addDynamicTemplateDatas($substitutions); -$email->addCustomArg(new \SendGrid\Mail\CustomArg("marketing1", "false")); -$email->addCustomArg(new \SendGrid\Mail\CustomArg("transactional1", "true")); -$email->addCustomArg(new \SendGrid\Mail\CustomArg("category", "name")); +$email->addCustomArg(new CustomArg("marketing1", "false")); +$email->addCustomArg(new CustomArg("transactional1", "true")); +$email->addCustomArg(new CustomArg("category", "name")); $customArgs = [ - new \SendGrid\Mail\CustomArg("marketing2", "true"), - new \SendGrid\Mail\CustomArg("transactional2", "false"), - new \SendGrid\Mail\CustomArg("category", "name") + new CustomArg("marketing2", "true"), + new CustomArg("transactional2", "false"), + new CustomArg("category", "name") ]; $email->addCustomArgs($customArgs); -$email->setSendAt(new \SendGrid\Mail\SendAt(1461775051)); +$email->setSendAt(new SendAt(1461775051)); // You can add a personalization index or personalization parameter to the above // methods to add and update multiple personalizations. You can learn more about @@ -518,28 +541,28 @@ $email->setSendAt(new \SendGrid\Mail\SendAt(1461775051)); // The values below this comment are global to an entire message -$email->setFrom(new \SendGrid\Mail\From("test@example.com", "Twilio SendGrid")); +$email->setFrom(new From("test@example.com", "Twilio SendGrid")); $email->setGlobalSubject( - new \SendGrid\Mail\Subject("Sending with Twilio SendGrid is Fun and Global 2") + new Subject("Sending with Twilio SendGrid is Fun and Global 2") ); -$plainTextContent = new \SendGrid\Mail\PlainTextContent( +$plainTextContent = new PlainTextContent( "and easy to do anywhere, even with PHP" ); -$htmlContent = new \SendGrid\Mail\HtmlContent( +$htmlContent = new HtmlContent( "and easy to do anywhere, even with PHP" ); $email->addContent($plainTextContent); $email->addContent($htmlContent); $contents = [ - new \SendGrid\Mail\Content("text/calendar", "Party Time!!"), - new \SendGrid\Mail\Content("text/calendar2", "Party Time 2!!") + new Content("text/calendar", "Party Time!!"), + new Content("text/calendar2", "Party Time 2!!") ]; $email->addContents($contents); $email->addAttachment( - new \SendGrid\Mail\Attachment( + new Attachment( "base64 encoded content1", "image/png", "banner.png", @@ -548,14 +571,14 @@ $email->addAttachment( ) ); $attachments = [ - new \SendGrid\Mail\Attachment( + new Attachment( "base64 encoded content2", "banner2.jpeg", "image/jpeg", "attachment", "Banner 3" ), - new \SendGrid\Mail\Attachment( + new Attachment( "base64 encoded content3", "banner3.gif", "image/gif", @@ -566,88 +589,88 @@ $attachments = [ $email->addAttachments($attachments); $email->setTemplateId( - new \SendGrid\Mail\TemplateId("d-13b8f94fbcae4ec6b75270d6cb59f932") + new TemplateId("d-13b8f94fbcae4ec6b75270d6cb59f932") ); -$email->addGlobalHeader(new \SendGrid\Mail\Header("X-Day", "Monday")); +$email->addGlobalHeader(new Header("X-Day", "Monday")); $globalHeaders = [ - new \SendGrid\Mail\Header("X-Month", "January"), - new \SendGrid\Mail\Header("X-Year", "2017") + new Header("X-Month", "January"), + new Header("X-Year", "2017") ]; $email->addGlobalHeaders($globalHeaders); $email->addSection( - new \SendGrid\Mail\Section( + new Section( "%section1%", "Substitution for Section 1 Tag" ) ); $sections = [ - new \SendGrid\Mail\Section( + new Section( "%section3%", "Substitution for Section 3 Tag" ), - new \SendGrid\Mail\Section( + new Section( "%section4%", "Substitution for Section 4 Tag" ) ]; $email->addSections($sections); -$email->addCategory(new \SendGrid\Mail\Category("Category 1")); +$email->addCategory(new Category("Category 1")); $categories = [ - new \SendGrid\Mail\Category("Category 2"), - new \SendGrid\Mail\Category("Category 3") + new Category("Category 2"), + new Category("Category 3") ]; $email->addCategories($categories); $email->setBatchId( - new \SendGrid\Mail\BatchId( + new BatchId( "MWQxZmIyODYtNjE1Ni0xMWU1LWI3ZTUtMDgwMDI3OGJkMmY2LWEzMmViMjYxMw" ) ); $email->setReplyTo( - new \SendGrid\Mail\ReplyTo( + new ReplyTo( "dx+replyto2@example.com", "DX Team Reply To 2" ) ); -$asm = new \SendGrid\Mail\Asm( - new \SendGrid\Mail\GroupId(1), - new \SendGrid\Mail\GroupsToDisplay([1,2,3,4]) +$asm = new Asm( + new GroupId(1), + new GroupsToDisplay([1,2,3,4]) ); $email->setAsm($asm); -$email->setIpPoolName(new \SendGrid\Mail\IpPoolName("23")); +$email->setIpPoolName(new IpPoolName("23")); -$mail_settings = new \SendGrid\Mail\MailSettings(); +$mail_settings = new MailSettings(); $mail_settings->setBccSettings( - new \SendGrid\Mail\BccSettings(true, "bcc@example.com") + new BccSettings(true, "bcc@example.com") ); $mail_settings->setBypassListManagement( - new \SendGrid\Mail\BypassListManagement(true) + new BypassListManagement(true) ); $mail_settings->setFooter( - new \SendGrid\Mail\Footer(true, "Footer", "Footer") + new Footer(true, "Footer", "Footer") ); -$mail_settings->setSandBoxMode(new \SendGrid\Mail\SandBoxMode(true)); +$mail_settings->setSandBoxMode(new SandBoxMode(true)); $mail_settings->setSpamCheck( - new \SendGrid\Mail\SpamCheck(true, 1, "http://mydomain.com") + new SpamCheck(true, 1, "http://mydomain.com") ); $email->setMailSettings($mail_settings); -$tracking_settings = new \SendGrid\Mail\TrackingSettings(); +$tracking_settings = new TrackingSettings(); $tracking_settings->setClickTracking( - new \SendGrid\Mail\ClickTracking(true, true) + new ClickTracking(true, true) ); $tracking_settings->setOpenTracking( - new \SendGrid\Mail\OpenTracking(true, "--sub--") + new OpenTracking(true, "--sub--") ); $tracking_settings->setSubscriptionTracking( - new \SendGrid\Mail\SubscriptionTracking( + new SubscriptionTracking( true, "subscribe", "subscribe", @@ -655,7 +678,7 @@ $tracking_settings->setSubscriptionTracking( ) ); $tracking_settings->setGanalytics( - new \SendGrid\Mail\Ganalytics( + new Ganalytics( true, "utm_source", "utm_medium", @@ -682,16 +705,12 @@ try { ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$email = new \SendGrid\Mail\Mail(); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\Mail; + +$email = new Mail(); $email->setFrom("test@example.com", "Example User"); $email->setSubject("Sending with Twilio SendGrid is Fun"); $email->addTo("test@example.com", "Example User"); @@ -714,25 +733,26 @@ OR ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$from = new \SendGrid\Mail\From("test@example.com", "Example User"); -$subject = new \SendGrid\Mail\Subject("Sending with Twilio SendGrid is Fun"); -$to = new \SendGrid\Mail\To("test@example.com", "Example User"); -$plainTextContent = new \SendGrid\Mail\PlainTextContent( +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\From; +use SendGrid\Mail\HtmlContent; +use SendGrid\Mail\Mail; +use SendGrid\Mail\PlainTextContent; +use SendGrid\Mail\Subject; +use SendGrid\Mail\To; + +$from = new From("test@example.com", "Example User"); +$subject = new Subject("Sending with Twilio SendGrid is Fun"); +$to = new To("test@example.com", "Example User"); +$plainTextContent = new PlainTextContent( "and easy to do anywhere, even with PHP" ); -$htmlContent = new \SendGrid\Mail\HtmlContent( +$htmlContent = new HtmlContent( "and easy to do anywhere, even with PHP" ); -$email = new \SendGrid\Mail\Mail( +$email = new Mail( $from, $to, $subject, @@ -755,16 +775,12 @@ try { ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$email = new \SendGrid\Mail\Mail(); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\Mail; + +$email = new Mail(); $email->setFrom("test@example.com", "Example User"); $tos = [ "test+test1@example.com" => "Example User1", @@ -792,28 +808,30 @@ OR ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases -$from = new \SendGrid\Mail\From("test@example.com", "Example User"); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\From; +use SendGrid\Mail\HtmlContent; +use SendGrid\Mail\Mail; +use SendGrid\Mail\PlainTextContent; +use SendGrid\Mail\Subject; +use SendGrid\Mail\To; + +$from = new From("test@example.com", "Example User"); $tos = [ - new \SendGrid\Mail\To("test+test1@example.com", "Example User1"), - new \SendGrid\Mail\To("test+test2@example.com", "Example User2"), - new \SendGrid\Mail\To("test+test3@example.com", "Example User3") + new To("test+test1@example.com", "Example User1"), + new To("test+test2@example.com", "Example User2"), + new To("test+test3@example.com", "Example User3") ]; -$subject = new \SendGrid\Mail\Subject("Sending with Twilio SendGrid is Fun"); -$plainTextContent = new \SendGrid\Mail\PlainTextContent( +$subject = new Subject("Sending with Twilio SendGrid is Fun"); +$plainTextContent = new PlainTextContent( "and easy to do anywhere, even with PHP" ); -$htmlContent = new \SendGrid\Mail\HtmlContent( +$htmlContent = new HtmlContent( "and easy to do anywhere, even with PHP" ); -$email = new \SendGrid\Mail\Mail( +$email = new Mail( $from, $tos, $subject, @@ -839,18 +857,19 @@ Note that [transactional templates](#transactional-templates) may be a better op ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$from = new \SendGrid\Mail\From("test@example.com", "Example User"); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\From; +use SendGrid\Mail\HtmlContent; +use SendGrid\Mail\Mail; +use SendGrid\Mail\PlainTextContent; +use SendGrid\Mail\Subject; +use SendGrid\Mail\To; + +$from = new From("test@example.com", "Example User"); $tos = [ - new \SendGrid\Mail\To( + new To( "test+test1@example.com", "Example User1", [ @@ -859,7 +878,7 @@ $tos = [ ], "Subject 1 -name-" ), - new \SendGrid\Mail\To( + new To( "test+test2@example.com", "Example User2", [ @@ -868,7 +887,7 @@ $tos = [ ], "Subject 2 -name-" ), - new \SendGrid\Mail\To( + new To( "test+test3@example.com", "Example User3", [ @@ -877,20 +896,20 @@ $tos = [ ] ) ]; -$subject = new \SendGrid\Mail\Subject("Hi -name-!"); // default subject +$subject = new Subject("Hi -name-!"); // default subject $globalSubstitutions = [ '-time-' => "2018-05-03 23:10:29" ]; -$plainTextContent = new \SendGrid\Mail\PlainTextContent( +$plainTextContent = new PlainTextContent( "Hello -name-, your github is -github- sent at -time-" ); -$htmlContent = new \SendGrid\Mail\HtmlContent( +$htmlContent = new HtmlContent( "Hello -name-, your github is here sent at -time-" ); -$email = new \SendGrid\Mail\Mail( +$email = new Mail( $from, $tos, - $subject, // or array of subjects, these take precendence + $subject, // or array of subjects, these take precedence $plainTextContent, $htmlContent, $globalSubstitutions @@ -911,18 +930,18 @@ OR ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -$from = new \SendGrid\Mail\From("test@example.com", "Example User"); +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\From; +use SendGrid\Mail\HtmlContent; +use SendGrid\Mail\Mail; +use SendGrid\Mail\PlainTextContent; +use SendGrid\Mail\To; + +$from = new From("test@example.com", "Example User"); $tos = [ - new \SendGrid\Mail\To( + new To( "test+test1@example.com", "Example User1", [ @@ -931,7 +950,7 @@ $tos = [ ], "Example User1 -name-" ), - new \SendGrid\Mail\To( + new To( "test+test2@example.com", "Example User2", [ @@ -940,7 +959,7 @@ $tos = [ ], "Example User2 -name-" ), - new \SendGrid\Mail\To( + new To( "test+test3@example.com", "Example User3", [ @@ -956,16 +975,16 @@ $subject = [ $globalSubstitutions = [ '-time-' => "2018-05-03 23:10:29" ]; -$plainTextContent = new \SendGrid\Mail\PlainTextContent( +$plainTextContent = new PlainTextContent( "Hello -name-, your github is -github- sent at -time-" ); -$htmlContent = new \SendGrid\Mail\HtmlContent( +$htmlContent = new HtmlContent( "Hello -name-, your github is here sent at -time-" ); -$email = new \SendGrid\Mail\Mail( +$email = new Mail( $from, $tos, - $subject, // or array of subjects, these take precendence + $subject, // or array of subjects, these take precedence $plainTextContent, $htmlContent, $globalSubstitutions @@ -1019,21 +1038,12 @@ I hope you are having a great day in {{ city }} :) ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -use \SendGrid\Mail\From as From; -use \SendGrid\Mail\To as To; -use \SendGrid\Mail\Subject as Subject; -use \SendGrid\Mail\PlainTextContent as PlainTextContent; -use \SendGrid\Mail\HtmlContent as HtmlContent; -use \SendGrid\Mail\Mail as Mail; +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use SendGrid\Mail\From; +use SendGrid\Mail\To; +use SendGrid\Mail\Mail; $from = new From("test@example.com", "Example User"); $tos = [ @@ -1084,7 +1094,13 @@ try { OR ```php -$email = new \SendGrid\Mail\Mail(); +/sendgrid-php.php'; + +use SendGrid\Mail\Mail; + +$email = new Mail(); $email->setFrom("test@sendgrid.com", "Example User"); $email->setSubject("I'm replacing the subject tag"); $email->addTo( @@ -1168,21 +1184,15 @@ I hope you are having a great day in -city- :) ```php /sendgrid-php.php"); -// If not using Composer, uncomment the above line and -// download sendgrid-php.zip from the latest release here, -// replacing with the path to the sendgrid-php.php file, -// which is included in the download: -// https://github.com/sendgrid/sendgrid-php/releases - -use \SendGrid\Mail\From as From; -use \SendGrid\Mail\To as To; -use \SendGrid\Mail\Subject as Subject; -use \SendGrid\Mail\PlainTextContent as PlainTextContent; -use \SendGrid\Mail\HtmlContent as HtmlContent; -use \SendGrid\Mail\Mail as Mail; +// Uncomment next line if you're not using a dependency loader (such as Composer) +// require_once '/sendgrid-php.php'; + +use \SendGrid\Mail\From; +use \SendGrid\Mail\To; +use \SendGrid\Mail\Subject; +use \SendGrid\Mail\PlainTextContent; +use \SendGrid\Mail\HtmlContent; +use \SendGrid\Mail\Mail; $from = new From("test@example.com", "Example User"); $tos = [ @@ -1240,7 +1250,13 @@ try { OR ```php -$email = new \SendGrid\Mail\Mail(); +/sendgrid-php.php'; + +use SendGrid\Mail\Mail; + +$email = new Mail(); $email->setFrom("test@sendgrid.com", "Example User"); $email->setSubject("I'm replacing the subject tag"); $email->addTo( @@ -1404,7 +1420,7 @@ In order to gain access to the Email Activity Feed API, you must [purchase](http # Deploying to Heroku -Use the button below to instantly setup your own Simple instance for sending email using sendgrid on Heroku. +Use the button below to instantly setup your own Simple instance for sending email using SendGrid on Heroku. Deploy @@ -1413,7 +1429,7 @@ Use the button below to instantly setup your own Simple instance for sending ema # Google App Engine Installation -Google App Engine installations with composer require the creation of file `php.ini` in the base folder(the same directory as the `app.yaml` file). You can read more about this file [here](https://cloud.google.com/appengine/docs/standard/php/config/php_ini). +Google App Engine installations with Composer require the creation of file `php.ini` in the base folder(the same directory as the `app.yaml` file). You can read more about this file [here](https://cloud.google.com/appengine/docs/standard/php/config/php_ini). The file `php.ini` should contain: diff --git a/examples/accesssettings/accesssettings.php b/examples/accesssettings/accesssettings.php index b55adc9aa..a409fe33e 100644 --- a/examples/accesssettings/accesssettings.php +++ b/examples/accesssettings/accesssettings.php @@ -1,9 +1,8 @@ client->api_keys()->_($api_key_id)->put($request_body); + $response = $sg->client->api_keys()->_($api_key_id)->put($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -78,7 +77,7 @@ $api_key_id = "test_url_param"; try { - $response = $sg->client->api_keys()->_($api_key_id)->patch($request_body); + $response = $sg->client->api_keys()->_($api_key_id)->patch($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -93,7 +92,7 @@ $api_key_id = "test_url_param"; try { - $response = $sg->client->api_keys()->_($api_key_id)->get(); + $response = $sg->client->api_keys()->_($api_key_id)->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -108,7 +107,7 @@ $api_key_id = "test_url_param"; try { - $response = $sg->client->api_keys()->_($api_key_id)->delete(); + $response = $sg->client->api_keys()->_($api_key_id)->delete(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/asm/asm.php b/examples/asm/asm.php index 9e3cd4fd8..273dafd87 100644 --- a/examples/asm/asm.php +++ b/examples/asm/asm.php @@ -1,9 +1,8 @@ client->asm()->groups()->post($request_body); + $response = $sg->client->asm()->groups()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -34,7 +33,7 @@ $query_params = json_decode('{"id": 1}'); try { - $response = $sg->client->asm()->groups()->get(null, $query_params); + $response = $sg->client->asm()->groups()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -47,14 +46,14 @@ // PATCH /asm/groups/{group_id} # $request_body = json_decode('{ - "description": "Suggestions for items our users might like.", - "id": 103, + "description": "Suggestions for items our users might like.", + "id": 103, "name": "Item Suggestions" }'); $group_id = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->patch($request_body); + $response = $sg->client->asm()->groups()->_($group_id)->patch($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -69,7 +68,7 @@ $group_id = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->get(); + $response = $sg->client->asm()->groups()->_($group_id)->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -84,7 +83,7 @@ $group_id = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->delete(); + $response = $sg->client->asm()->groups()->_($group_id)->delete(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -98,14 +97,14 @@ $request_body = json_decode('{ "recipient_emails": [ - "test1@example.com", + "test1@example.com", "test2@example.com" ] }'); $group_id = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body); + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -120,7 +119,7 @@ $group_id = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get(); + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -134,15 +133,15 @@ $request_body = json_decode('{ "recipient_emails": [ - "exists1@example.com", - "exists2@example.com", + "exists1@example.com", + "exists2@example.com", "doesnotexists@example.com" ] }'); $group_id = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->search()->post($request_body); + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->search()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -158,7 +157,7 @@ $email = "test_url_param"; try { - $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete(); + $response = $sg->client->asm()->groups()->_($group_id)->suppressions()->_($email)->delete(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -172,7 +171,7 @@ try { - $response = $sg->client->asm()->suppressions()->get(); + $response = $sg->client->asm()->suppressions()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -186,13 +185,13 @@ $request_body = json_decode('{ "recipient_emails": [ - "test1@example.com", + "test1@example.com", "test2@example.com" ] }'); try { - $response = $sg->client->asm()->suppressions()->global()->post($request_body); + $response = $sg->client->asm()->suppressions()->global()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -207,7 +206,7 @@ $email = "test_url_param"; try { - $response = $sg->client->asm()->suppressions()->global()->_($email)->get(); + $response = $sg->client->asm()->suppressions()->global()->_($email)->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -222,7 +221,7 @@ $email = "test_url_param"; try { - $response = $sg->client->asm()->suppressions()->global()->_($email)->delete(); + $response = $sg->client->asm()->suppressions()->global()->_($email)->delete(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -237,7 +236,7 @@ $email = "test_url_param"; try { - $response = $sg->client->asm()->suppressions()->_($email)->get(); + $response = $sg->client->asm()->suppressions()->_($email)->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/browsers/browsers.php b/examples/browsers/browsers.php index c54162155..9e50a994f 100644 --- a/examples/browsers/browsers.php +++ b/examples/browsers/browsers.php @@ -1,9 +1,8 @@

Check out our spring line!

", - "ip_pool": "marketing", + ], + "custom_unsubscribe_url": "", + "html_content": "

Check out our spring line!

", + "ip_pool": "marketing", "list_ids": [ - 110, + 110, 124 - ], - "plain_content": "Check out our spring line!", + ], + "plain_content": "Check out our spring line!", "segment_ids": [ 110 - ], - "sender_id": 124451, - "subject": "New Products for Spring!", - "suppression_group_id": 42, + ], + "sender_id": 124451, + "subject": "New Products for Spring!", + "suppression_group_id": 42, "title": "March Newsletter" }'); try { - $response = $sg->client->campaigns()->post($request_body); + $response = $sg->client->campaigns()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -49,7 +48,7 @@ $query_params = json_decode('{"limit": 1, "offset": 1}'); try { - $response = $sg->client->campaigns()->get(null, $query_params); + $response = $sg->client->campaigns()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -64,16 +63,16 @@ $request_body = json_decode('{ "categories": [ "summer line" - ], - "html_content": "

Check out our summer line!

", - "plain_content": "Check out our summer line!", - "subject": "New Products for Summer!", + ], + "html_content": "

Check out our summer line!

", + "plain_content": "Check out our summer line!", + "subject": "New Products for Summer!", "title": "May Newsletter" }'); $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->patch($request_body); + $response = $sg->client->campaigns()->_($campaign_id)->patch($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -88,7 +87,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->get(); + $response = $sg->client->campaigns()->_($campaign_id)->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -103,7 +102,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->delete(); + $response = $sg->client->campaigns()->_($campaign_id)->delete(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -121,7 +120,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body); + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->patch($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -139,7 +138,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body); + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -154,7 +153,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->schedules()->get(); + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -169,7 +168,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->schedules()->delete(); + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->delete(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -184,7 +183,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->schedules()->now()->post(); + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->now()->post(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -202,7 +201,7 @@ $campaign_id = "test_url_param"; try { - $response = $sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body); + $response = $sg->client->campaigns()->_($campaign_id)->schedules()->test()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/categories/categories.php b/examples/categories/categories.php index 443029629..7510026aa 100644 --- a/examples/categories/categories.php +++ b/examples/categories/categories.php @@ -1,9 +1,8 @@ client->categories()->get(null, $query_params); + $response = $sg->client->categories()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -30,7 +29,7 @@ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "offset": 1, "start_date": "2016-01-01", "categories": "test_string"}'); try { - $response = $sg->client->categories()->stats()->get(null, $query_params); + $response = $sg->client->categories()->stats()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -45,7 +44,7 @@ $query_params = json_decode('{"end_date": "2016-04-01", "aggregated_by": "day", "limit": 1, "sort_by_metric": "test_string", "offset": 1, "start_date": "2016-01-01", "sort_by_direction": "asc"}'); try { - $response = $sg->client->categories()->stats()->sums()->get(null, $query_params); + $response = $sg->client->categories()->stats()->sums()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/clients/clients.php b/examples/clients/clients.php index 4e31b21eb..a4d85c9a5 100644 --- a/examples/clients/clients.php +++ b/examples/clients/clients.php @@ -1,9 +1,8 @@ client->clients()->stats()->get(null, $query_params); + $response = $sg->client->clients()->stats()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -31,7 +30,7 @@ $client_type = "test_url_param"; try { - $response = $sg->client->clients()->_($client_type)->stats()->get(null, $query_params); + $response = $sg->client->clients()->_($client_type)->stats()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/contactdb/contactdb.php b/examples/contactdb/contactdb.php index b2ee7b20d..9d0387dab 100644 --- a/examples/contactdb/contactdb.php +++ b/examples/contactdb/contactdb.php @@ -1,9 +1,8 @@ client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params); + $response = $sg->client->contactdb()->segments()->_($segment_id)->patch($request_body, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -506,7 +505,7 @@ $segment_id = "test_url_param"; try { - $response = $sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params); + $response = $sg->client->contactdb()->segments()->_($segment_id)->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -522,7 +521,7 @@ $segment_id = "test_url_param"; try { - $response = $sg->client->contactdb()->segments()->_($segment_id)->delete(null, $query_params); + $response = $sg->client->contactdb()->segments()->_($segment_id)->delete(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -538,7 +537,7 @@ $segment_id = "test_url_param"; try { - $response = $sg->client->contactdb()->segments()->_($segment_id)->recipients()->get(null, $query_params); + $response = $sg->client->contactdb()->segments()->_($segment_id)->recipients()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/devices/devices.php b/examples/devices/devices.php index a6b9d0870..ffe0878f0 100644 --- a/examples/devices/devices.php +++ b/examples/devices/devices.php @@ -1,8 +1,8 @@ client->devices()->stats()->get(null, $query_params); + $response = $sg->client->devices()->stats()->get(null, $query_params); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/geo/geo.php b/examples/geo/geo.php index 708ca5d18..a97146ab7 100644 --- a/examples/geo/geo.php +++ b/examples/geo/geo.php @@ -1,9 +1,8 @@ /vendor/autoload.php'; -// comment out the above line if not using Composer -// require("./sendgrid-php.php"); -// If not using Composer, uncomment the above line +// Next line will load dependencies to run this example +// Please refer to the README how to use in your project +require_once __DIR__ . '/../../../sendgrid-php.php'; -// This will build an HTML form to be embedded in your page. This form allows users to subscribe using their name and email. +// This will build an HTML form to be embedded in your page. +// This form allows users to subscribe using their name and email. function buildRecipientForm($url = 'http://www.example.com/recipientFormSubmit') { $form = (string) new \SendGrid\Contacts\RecipientForm($url); echo $form . PHP_EOL; } -// This will accept a form submission from the above form. Will create a new Recipient, adding them to "contactdb". Note, it does not add the recipient to any list. +// This will accept a form submission from the above form. Will create a new Recipient, +// adding them to "contactdb". Note, it does not add the recipient to any list. function recipientFormSubmit() { $apiKey = getenv('SENDGRID_API_KEY'); @@ -41,9 +40,9 @@ function recipientFormSubmit() } ]' ); - + try { - $response = $sg->client->contactdb()->recipients()->post($request_body); + $response = $sg->client->contactdb()->recipients()->post($request_body); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; @@ -54,7 +53,3 @@ function recipientFormSubmit() buildRecipientForm(); // This will build and output an HTML form recipientFormSubmit(); // This will simulate a form submission and will output the response. - -?> - - diff --git a/examples/helpers/mail/example.php b/examples/helpers/mail/example.php index f4cbdd54f..fc7b8a4c7 100644 --- a/examples/helpers/mail/example.php +++ b/examples/helpers/mail/example.php @@ -1,10 +1,8 @@ /vendor/autoload.php'; -// comment out the above line if not using Composer -// require("./sendgrid-php.php"); -// If not using Composer, uncomment the above line +// Next line will load dependencies to run this example +// Please refer to the README how to use in your project +require_once __DIR__ . '/../../../sendgrid-php.php'; use SendGrid\Mail\To; use SendGrid\Mail\Cc; diff --git a/examples/helpers/stats/example.php b/examples/helpers/stats/example.php index 7886411ff..b56228ff1 100644 --- a/examples/helpers/stats/example.php +++ b/examples/helpers/stats/example.php @@ -1,10 +1,8 @@ /vendor/autoload.php'; -// comment out the above line if not using Composer -// require("./sendgrid-php.php"); -// If not using Composer, uncomment the above line +// Next line will load dependencies to run this example +// Please refer to the README how to use in your project +require_once __DIR__ . '/../../../sendgrid-php.php'; $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); diff --git a/examples/ips/ips.php b/examples/ips/ips.php index bf7c45301..33973e02f 100644 --- a/examples/ips/ips.php +++ b/examples/ips/ips.php @@ -1,9 +1,8 @@

Hello, world!

" } - ], + ], "custom_args": { - "New Argument 1": "New Value 1", - "activationAttempt": "1", + "New Argument 1": "New Value 1", + "activationAttempt": "1", "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]" - }, + }, "from": { - "email": "sam.smith@example.com", + "email": "sam.smith@example.com", "name": "Sam Smith" - }, - "headers": {}, - "ip_pool_name": "[YOUR POOL NAME GOES HERE]", + }, + "headers": {}, + "ip_pool_name": "[YOUR POOL NAME GOES HERE]", "mail_settings": { "bcc": { - "email": "ben.doe@example.com", + "email": "ben.doe@example.com", "enable": true - }, + }, "bypass_list_management": { "enable": true - }, + }, "footer": { - "enable": true, - "html": "

Thanks
The Twilio SendGrid Team

", + "enable": true, + "html": "

Thanks
The Twilio SendGrid Team

", "text": "Thanks,/n The Twilio SendGrid Team" - }, + }, "sandbox_mode": { "enable": false - }, + }, "spam_check": { - "enable": true, - "post_to_url": "http://example.com/compliance", + "enable": true, + "post_to_url": "http://example.com/compliance", "threshold": 3 } - }, + }, "personalizations": [ { "bcc": [ { - "email": "sam.doe@example.com", + "email": "sam.doe@example.com", "name": "Sam Doe" } - ], + ], "cc": [ { - "email": "jane.doe@example.com", + "email": "jane.doe@example.com", "name": "Jane Doe" } - ], + ], "custom_args": { - "New Argument 1": "New Value 1", - "activationAttempt": "1", + "New Argument 1": "New Value 1", + "activationAttempt": "1", "customerAccountNumber": "[CUSTOMER ACCOUNT NUMBER GOES HERE]" - }, + }, "headers": { - "X-Accept-Language": "en", + "X-Accept-Language": "en", "X-Mailer": "MyApp" - }, - "send_at": 1409348513, - "subject": "Hello, World!", + }, + "send_at": 1409348513, + "subject": "Hello, World!", "substitutions": { - "id": "substitutions", + "id": "substitutions", "type": "object" - }, + }, "to": [ { - "email": "john.doe@example.com", + "email": "john.doe@example.com", "name": "John Doe" } ] } - ], + ], "reply_to": { - "email": "sam.smith@example.com", + "email": "sam.smith@example.com", "name": "Sam Smith" - }, + }, "sections": { "section": { - ":sectionName1": "section 1 text", + ":sectionName1": "section 1 text", ":sectionName2": "section 2 text" } - }, - "send_at": 1409348513, - "subject": "Hello, World!", - "template_id": "[YOUR TEMPLATE ID GOES HERE]", + }, + "send_at": 1409348513, + "subject": "Hello, World!", + "template_id": "[YOUR TEMPLATE ID GOES HERE]", "tracking_settings": { "click_tracking": { - "enable": true, + "enable": true, "enable_text": true - }, + }, "ganalytics": { - "enable": true, - "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]", - "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]", - "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]", - "utm_name": "[NAME OF YOUR CAMPAIGN]", + "enable": true, + "utm_campaign": "[NAME OF YOUR REFERRER SOURCE]", + "utm_content": "[USE THIS SPACE TO DIFFERENTIATE YOUR EMAIL FROM ADS]", + "utm_medium": "[NAME OF YOUR MARKETING MEDIUM e.g. email]", + "utm_name": "[NAME OF YOUR CAMPAIGN]", "utm_term": "[IDENTIFY PAID KEYWORDS HERE]" - }, + }, "open_tracking": { - "enable": true, + "enable": true, "substitution_tag": "%opentrack" - }, + }, "subscription_tracking": { - "enable": true, - "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.", - "substitution_tag": "<%click here%>", + "enable": true, + "html": "If you would like to unsubscribe and stop receiving these emails <% clickhere %>.", + "substitution_tag": "<%click here%>", "text": "If you would like to unsubscribe and stop receiving these emails <% click here %>." } } diff --git a/examples/mailboxproviders/mailboxproviders.php b/examples/mailboxproviders/mailboxproviders.php index 6cf1be3b8..d0fd56716 100644 --- a/examples/mailboxproviders/mailboxproviders.php +++ b/examples/mailboxproviders/mailboxproviders.php @@ -1,9 +1,8 @@ " }'); diff --git a/examples/partnersettings/partnersettings.php b/examples/partnersettings/partnersettings.php index 17d528750..fde977dfb 100644 --- a/examples/partnersettings/partnersettings.php +++ b/examples/partnersettings/partnersettings.php @@ -1,9 +1,8 @@ client->scopes()->get(); + $response = $sg->client->scopes()->get(); print $response->statusCode() . "\n"; print_r($response->headers()); print $response->body() . "\n"; diff --git a/examples/senderauthentication/senderauthentication.php b/examples/senderauthentication/senderauthentication.php index d18816b04..333074c47 100644 --- a/examples/senderauthentication/senderauthentication.php +++ b/examples/senderauthentication/senderauthentication.php @@ -1,9 +1,8 @@ ", - "name": "example_version_name", - "plain_content": "<%body%>", - "subject": "<%subject%>", + "active": 1, + "html_content": "<%body%>", + "name": "example_version_name", + "plain_content": "<%body%>", + "subject": "<%subject%>", "template_id": "ddb96bbc-9b92-425e-8979-99464621b543" }'); $template_id = "test_url_param"; @@ -116,10 +115,10 @@ // PATCH /templates/{template_id}/versions/{version_id} # $request_body = json_decode('{ - "active": 1, - "html_content": "<%body%>", - "name": "updated_example_name", - "plain_content": "<%body%>", + "active": 1, + "html_content": "<%body%>", + "name": "updated_example_name", + "plain_content": "<%body%>", "subject": "<%subject%>" }'); $template_id = "test_url_param"; diff --git a/examples/trackingsettings/trackingsettings.php b/examples/trackingsettings/trackingsettings.php index 8d58b6303..98477d788 100644 --- a/examples/trackingsettings/trackingsettings.php +++ b/examples/trackingsettings/trackingsettings.php @@ -1,8 +1,8 @@