### Install with Composer Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-sendgrid ``` -------------------------------- ### List and Get Campaigns Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md List campaigns with a page size and retrieve a specific campaign by ID. ```php $campaigns = Sendgrid::campaigns()->list(pageSize: 10); $campaign = Sendgrid::campaigns()->get('campaign-id'); ``` -------------------------------- ### Sendgrid::campaigns()->get Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Retrieves a specific campaign by ID. ```APIDOC ## Sendgrid::campaigns()->get ### Description Retrieves a specific campaign by ID. ### Method GET ### Endpoint /campaigns/{campaign_id} ### Parameters #### Path Parameters - **campaign_id** (string) - Required - The campaign ID. ### Response #### Success Response (2xx) Returns the campaign details. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Get Stats Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Retrieve stats for a date range. ```php $stats = Sendgrid::stats()->get(startDate: '2026-01-01', endDate: '2026-01-31'); ``` -------------------------------- ### Sendgrid::stats()->get Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Retrieves email statistics for a date range. ```APIDOC ## Sendgrid::stats()->get ### Description Retrieves email statistics for a date range. ### Method GET ### Endpoint /stats ### Parameters #### Query Parameters - **startDate** (string) - Required - Start date in YYYY-MM-DD format. - **endDate** (string) - Optional - End date in YYYY-MM-DD format. ### Response #### Success Response (2xx) Returns statistics data. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### SendGrid Config File Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Configuration file for the package, with environment variable fallbacks. ```php // config/sendgrid.php return [ 'api_key' => env('SENDGRID_API_KEY', ''), 'from_email' => env('SENDGRID_FROM_EMAIL', ''), 'from_name' => env('SENDGRID_FROM_NAME', ''), 'base_url' => env('SENDGRID_BASE_URL', 'https://api.sendgrid.com/v3'), ]; ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Runs the test suite for the Laravel SendGrid package using Composer. ```bash composer test ``` -------------------------------- ### Publish SendGrid Config Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Publish the configuration file to your Laravel application. ```bash php artisan vendor:publish --tag=sendgrid-config ``` -------------------------------- ### Send Email with Sendgrid Facade Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Send emails with plain text/HTML, multiple recipients, cc/bcc, custom from, reply-to, and dynamic templates. If 'from'/'from_name' are omitted, the config values are used. ```php use JeffersonGoncalves\LaravelSendgrid\Facades\Sendgrid; Sendgrid::send([ 'to' => 'jane@example.com', 'subject' => 'Welcome!', 'text' => 'Hi Jane, welcome aboard.', 'html' => '
Hi Jane, welcome aboard.
', ]); // Multiple recipients, cc/bcc, custom from, reply-to Sendgrid::send([ 'to' => ['jane@example.com', 'john@example.com'], 'from' => 'no-reply@example.com', 'from_name' => 'Example App', 'subject' => 'Welcome!', 'html' => 'Welcome aboard.
', 'cc' => 'cc@example.com', 'bcc' => 'bcc@example.com', 'reply_to' => 'support@example.com', ]); // Dynamic templates Sendgrid::send([ 'to' => 'jane@example.com', 'template_id' => 'd-1234567890', 'dynamic_template_data' => ['name' => 'Jane'], ]); ``` -------------------------------- ### Set SendGrid Environment Variables Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Set your SendGrid API key and default sender details in the .env file. ```env SENDGRID_API_KEY=your-api-key SENDGRID_FROM_EMAIL=no-reply@example.com SENDGRID_FROM_NAME="Example App" ``` -------------------------------- ### Sendgrid::campaigns()->list Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Lists campaigns from SendGrid with optional page size. ```APIDOC ## Sendgrid::campaigns()->list ### Description Lists campaigns from SendGrid. ### Method GET ### Endpoint /campaigns ### Parameters #### Query Parameters - **pageSize** (integer) - Optional - Number of campaigns per page. ### Response #### Success Response (2xx) Returns a list of campaigns. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Manage Contacts Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md List, add, and search contacts using the contacts resource. ```php $contacts = Sendgrid::contacts()->list(); Sendgrid::contacts()->add( email: 'jane@example.com', firstName: 'Jane', lastName: 'Doe', listIds: ['list-id'], ); $result = Sendgrid::contacts()->search('email LIKE \'jane%\''); ``` -------------------------------- ### List Bounces Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md List bounces with a limit. ```php $bounces = Sendgrid::bounces()->list(limit: 50); ``` -------------------------------- ### Sendgrid::contacts()->list Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Lists contacts from SendGrid. ```APIDOC ## Sendgrid::contacts()->list ### Description Lists contacts from SendGrid. ### Method GET ### Endpoint /contactdb/recipients ### Parameters None documented. ### Response #### Success Response (2xx) Returns a list of contacts. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Sendgrid::spamReports()->list Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Lists spam reports with optional limit. ```APIDOC ## Sendgrid::spamReports()->list ### Description Lists spam reports. ### Method GET ### Endpoint /suppression/spam_reports ### Parameters #### Query Parameters - **limit** (integer) - Optional - Maximum number of spam reports to return. ### Response #### Success Response (2xx) Returns a list of spam reports. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Sendgrid::contacts()->add Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Adds a contact to SendGrid with optional first name, last name, and list IDs. ```APIDOC ## Sendgrid::contacts()->add ### Description Adds a contact to SendGrid. ### Method POST ### Endpoint /contactdb/recipients ### Parameters #### Request Body - **email** (string) - Required - Contact email address. - **firstName** (string) - Optional - Contact first name. - **lastName** (string) - Optional - Contact last name. - **listIds** (array) - Optional - Array of list IDs to add the contact to. ### Request Example ```json { "email": "jane@example.com", "firstName": "Jane", "lastName": "Doe", "listIds": ["list-id"] } ``` ### Response #### Success Response (2xx) No response body documented. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### List Spam Reports Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md List spam reports with a limit. ```php $reports = Sendgrid::spamReports()->list(limit: 50); ``` -------------------------------- ### Handle SendgridException Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Catch SendgridException on non-2xx responses and log the error body. ```php use JeffersonGoncalves\LaravelSendgrid\Exceptions\SendgridException; try { Sendgrid::send(['to' => 'jane@example.com', 'subject' => 'Hi', 'text' => 'Hi']); } catch (SendgridException $e) { logger()->error($e->getMessage(), $e->errorBody()); } ``` -------------------------------- ### Sendgrid::bounces()->list Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Lists bounced emails with optional limit. ```APIDOC ## Sendgrid::bounces()->list ### Description Lists bounced emails. ### Method GET ### Endpoint /suppression/bounces ### Parameters #### Query Parameters - **limit** (integer) - Optional - Maximum number of bounces to return. ### Response #### Success Response (2xx) Returns a list of bounces. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Sendgrid::send Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Sends an email via SendGrid with support for plain text/HTML, dynamic templates, cc/bcc, and reply-to. ```APIDOC ## Sendgrid::send ### Description Sends an email via SendGrid. Supports plain text/HTML content, dynamic templates, cc/bcc, and reply-to. ### Method POST ### Endpoint /mail/send ### Parameters #### Request Body - **to** (string|array) - Required - Recipient email address or array of recipient email addresses. - **subject** (string) - Required - Email subject. - **text** (string) - Optional - Plain text content. - **html** (string) - Optional - HTML content. - **from** (string) - Optional - Sender email address. Defaults to config('sendgrid.from_email'). - **from_name** (string) - Optional - Sender name. Defaults to config('sendgrid.from_name'). - **cc** (string|array) - Optional - Carbon copy recipient(s). - **bcc** (string|array) - Optional - Blind carbon copy recipient(s). - **reply_to** (string) - Optional - Reply-to email address. - **template_id** (string) - Optional - SendGrid dynamic template ID. - **dynamic_template_data** (array) - Optional - Data for dynamic template variables. ### Request Example ```json { "to": "jane@example.com", "subject": "Welcome!", "text": "Hi Jane, welcome aboard.", "html": "Hi Jane, welcome aboard.
" } ``` ### Response #### Success Response (2xx) No response body documented. #### Error Response Throws SendgridException with the original API error body on any non-2xx response. ``` -------------------------------- ### Sendgrid::contacts()->search Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Searches contacts in SendGrid using a query expression. ```APIDOC ## Sendgrid::contacts()->search ### Description Searches contacts in SendGrid using a query expression. ### Method POST ### Endpoint /contactdb/recipients/search ### Parameters #### Request Body - **query** (string) - Required - Search query expression (e.g., "email LIKE 'jane%'"). ### Request Example ```json { "query": "email LIKE 'jane%'" } ``` ### Response #### Success Response (2xx) Returns search results. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Sendgrid::validateEmail Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Validates an email address using SendGrid's email validation service. ```APIDOC ## Sendgrid::validateEmail ### Description Validates an email address using SendGrid's email validation service. ### Method POST ### Endpoint /validations/email ### Parameters #### Request Body - **email** (string) - Required - Email address to validate. ### Request Example ```json { "email": "jane@example.com" } ``` ### Response #### Success Response (2xx) Returns validation result. #### Error Response Throws SendgridException on non-2xx response. ``` -------------------------------- ### Validate Email Source: https://github.com/jeffersongoncalves/laravel-sendgrid/blob/main/README.md Validate an email address. ```php $result = Sendgrid::validateEmail('jane@example.com'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.