Skip to content

Integrate SendGrid into your application for seamless email communication using the API method.

Notifications You must be signed in to change notification settings

abanoubtalaatr/Send-Grid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

SendGrid Integration

Integrate SendGrid into your application for seamless email communication using the API method.

There are two ways to integrate:

  • SMTP
  • API (this documentation focuses on API integration)

Table of Contents

Prerequisites

  1. Visit the official SendGrid website.
  2. Navigate to Sender Authentication.
  3. Click "Create new Sender," complete all requirements, and ensure you provide a valid email for verification. Save the API key generated during this process.
  4. Delete any configuration for email if exists.
  5. Set the following variables in your .env file:
    • MAIL_FROM_ADDRESS
    • MAIL_FROM_NAME
    • SENDGRID_API_KEY

Installation

Execute the following command to install the SendGrid package using Composer:

$ composer require sendgrid/sendgrid

Usage

  • (new SendGridService())->sendMail("Reject Email", 'abanoubtalaat555@gmail.com',$data,'mail.reject_driver');
    • Must Provide
      • Email subject
      • Email Address
      • Data will pass it to view
      • Email View
class SendGridService
{
    public $email;
    
    public function __construct()
    {
        $this->email = new \SendGrid\Mail\Mail();
    }
    
    public function sendMail($subject, $to, $data, $viewPath)
    {
        $this->email->setFrom(env("MAIL_FROM_ADDRESS"), env("MAIL_FROM_NAME"));
        $this->email->setSubject($subject);
        $this->email->addTo($to);
        $this->email->addContent("text/html", view($viewPath, compact('data'))->render());
        
        $sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
        $sendgrid->send($this->email);
    }
}

About

Integrate SendGrid into your application for seamless email communication using the API method.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published