diff --git a/README.md b/README.md index ac85b12..7348e1c 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # Laravel SendGrid Example -## Laravel Versions - -### Laravel 7 -For Laravel 7, install v3 of `s-ichikawa/laravel-sendgrid-driver`. - -### Laravel 6 -For Laravel 6, install v2. Also you use `MAIL_DRIVER` instead of of `MAIL_MAILER`. - ## Etc ### Command diff --git a/app/Console/Commands/EmailSendTestCommand.php b/app/Console/Commands/EmailSendTestCommand.php index 856742f..1a02fe8 100644 --- a/app/Console/Commands/EmailSendTestCommand.php +++ b/app/Console/Commands/EmailSendTestCommand.php @@ -3,8 +3,8 @@ namespace App\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Mail\Message; -use Sichikawa\LaravelSendgridDriver\Transport\SendgridTransport; +use SendGrid; +use SendGrid\Mail\Mail; class EmailSendTestCommand extends Command { @@ -34,6 +34,7 @@ public function __construct() /** * Execute the console command. + * @throws SendGrid\Mail\TypeException */ public function handle() { @@ -41,27 +42,20 @@ public function handle() throw new \LogicException('You must have the MAIL_FROM_ADDRESS env var set.'); } - \Mail::send([], [], function (Message $message) { - /** @noinspection PhpParamsInspection */ - $message - ->to($this->option('to')) - ->embedData([ - 'personalizations' => [ - [ - 'dynamic_template_data' => [ - 'title' => 'Subject', - 'name' => 's-ichikawa', - ], - ], - ], - 'asm' => [ - 'group_id' => (int) config('services.sendgrid.unsubscribe_group_id') - ], - 'template_id' => config('services.sendgrid.template_id'), - 'dynamic_template_data' => [ - 'titleText' => 'Dynamic Title Text!', - ], - ], SendgridTransport::SMTP_API_NAME); - }); + $sg = new SendGrid(config('services.sendgrid.api_key')); + $email = new Mail(); + $email->setFrom(config('mail.from.address'), config('mail.from.name')); + $email->addTo($this->option('to'), 'Test user'); + $email->setAsm((int) config('services.sendgrid.unsubscribe_group_id')); + $email->setTemplateId(config('services.sendgrid.template_id')); + $email->addDynamicTemplateDatas([ + 'titleText' => 'Dynamic Title Text!', + ]); + $emailResponse = $sg->send($email); + if (($statusCode = $emailResponse->statusCode()) !== 202) { + throw new \RuntimeException("Could not send email. Status code $statusCode:\n{$emailResponse->body()}"); + } + + echo "Email sent.\n"; } } diff --git a/composer.json b/composer.json index 7b117a9..42cc9fb 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "guzzlehttp/guzzle": "^6.3", "laravel/framework": "^7.0", "laravel/tinker": "^2.0", - "s-ichikawa/laravel-sendgrid-driver": "^3" + "sendgrid/sendgrid": "^7.4" }, "require-dev": { "facade/ignition": "^2.0", diff --git a/composer.lock b/composer.lock index 13a04ca..e155f97 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9ce2aeff08bc4557f3531d9f775bf511", + "content-hash": "6c9b916afabf99375b77b6ba6294e82f", "packages": [ { "name": "asm89/stack-cors", @@ -1965,45 +1965,30 @@ "time": "2020-03-29T20:13:32+00:00" }, { - "name": "s-ichikawa/laravel-sendgrid-driver", - "version": "3.0.1", + "name": "sendgrid/php-http-client", + "version": "3.10.5", "source": { "type": "git", - "url": "https://github.com/s-ichikawa/laravel-sendgrid-driver.git", - "reference": "b04c2f3446d07560ba154b62cb4a62626d6c35d6" + "url": "https://github.com/sendgrid/php-http-client.git", + "reference": "931a5a426fa3c3e31ecd8ad15597b2b183dad5db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s-ichikawa/laravel-sendgrid-driver/zipball/b04c2f3446d07560ba154b62cb4a62626d6c35d6", - "reference": "b04c2f3446d07560ba154b62cb4a62626d6c35d6", + "url": "https://api.github.com/repos/sendgrid/php-http-client/zipball/931a5a426fa3c3e31ecd8ad15597b2b183dad5db", + "reference": "931a5a426fa3c3e31ecd8ad15597b2b183dad5db", "shasum": "" }, "require": { - "guzzlehttp/guzzle": "^6.3", - "illuminate/mail": ">=7.0", - "phpoption/phpoption": "^1.7", - "vlucas/phpdotenv": "^4.1" + "php": ">=5.6" }, "require-dev": { - "illuminate/container": ">=7.0", - "illuminate/filesystem": ">=7.0", - "laravel/helpers": "^1.2", - "phpunit/phpunit": "^8.5" - }, - "suggest": { - "s-ichikawa/sendgrid-api-builder": "support to build json for sendgrid api" + "phpunit/phpunit": "~4.4", + "squizlabs/php_codesniffer": "~2.0" }, "type": "library", - "extra": { - "laravel": { - "providers": [ - "Sichikawa\\LaravelSendgridDriver\\SendgridTransportServiceProvider" - ] - } - }, "autoload": { "psr-4": { - "Sichikawa\\LaravelSendgridDriver\\": "src" + "SendGrid\\": "lib/" } }, "notification-url": "https://packagist.org/downloads/", @@ -2012,16 +1997,80 @@ ], "authors": [ { - "name": "shingo.ichikawa", - "email": "ichikawa.shingo.0829@gmail.com" + "name": "Matt Bernier", + "email": "dx@sendgrid.com" + }, + { + "name": "Elmer Thomas", + "email": "ethomas@twilio.com" } ], - "description": "This library adds a 'sendgrid' mail driver to Laravel.", + "description": "HTTP REST client, simplified for PHP", + "homepage": "http://github.com/sendgrid/php-http-client", "keywords": [ - "laravel", + "api", + "fluent", + "http", + "rest", "sendgrid" ], - "time": "2020-03-16T15:19:34+00:00" + "time": "2020-03-18T19:45:45+00:00" + }, + { + "name": "sendgrid/sendgrid", + "version": "7.4.5", + "source": { + "type": "git", + "url": "https://github.com/sendgrid/sendgrid-php.git", + "reference": "21231bb2f9694007da80a9d39b878c65867f8ca8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sendgrid/sendgrid-php/zipball/21231bb2f9694007da80a9d39b878c65867f8ca8", + "reference": "21231bb2f9694007da80a9d39b878c65867f8ca8", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-openssl": "*", + "php": ">=5.6", + "sendgrid/php-http-client": "~3.10" + }, + "replace": { + "sendgrid/sendgrid-php": "*" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.9 || ^6.4.3", + "squizlabs/php_codesniffer": "3.*", + "swaggest/json-diff": "^3.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "SendGrid\\Mail\\": "lib/mail/", + "SendGrid\\Contacts\\": "lib/contacts/", + "SendGrid\\Stats\\": "lib/stats/" + }, + "files": [ + "lib/SendGrid.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "This library allows you to quickly and easily send emails through Twilio SendGrid using PHP.", + "homepage": "http://github.com/sendgrid/sendgrid-php", + "keywords": [ + "email", + "grid", + "send", + "sendgrid", + "twilio sendgrid" + ], + "time": "2020-03-18T19:53:23+00:00" }, { "name": "swiftmailer/swiftmailer",