PHP Classes

How to Send Email Messages Using the PHP Gmail OAuth2 Transport Package Laravel Gmail OAuth2: Send messages via Gmail SMTP server using OAuth2

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-04-15 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 31 This week: 1All time: 11,039 This week: 69Up
Version License PHP version Categories
laravel-gmail-oauth2 1.0Custom (specified...7Email, Networking, Libraries, PHP 7
Description 

Author

This package can send messages via Gmail SMTP server using OAuth.

It provides a Gmail service class for Laravel applications to send email messages.

The package provides a transport class that uses OAuth2 tokens to send messages via the Gmail SMTP server.

Innovation Award
PHP Programming Innovation award nominee
April 2024
Nominee
Vote
Gmail is a popular email service. Its SMTP server allows users to send emails from external programs.

Nowadays, to send email messages using the accessible version of Gmail, applications need to use the OAuth2 protocol to pass an authentication token.

This package provides a service class for Laravel applications and a transport class to implement the OAuth2 protocol.

This way, developers using the Laravel framework can implement applications that send email via Gmail using the free version.

Manuel Lemos
Picture of Iago Felicio
  Performance   Level  
Name: Iago Felicio <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: 30
All time rank: 4510368 in Brazil Brazil
Week rank: 78 Up5 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

Instructions

Install the package using composer as described in the README file.

Then, follow steps 1 and 2, depending on the version of Laravel you are using, to configure the package.

Documentation

Send emails with Gmail OAuth2 credentials

Latest Version on Packagist Total Downloads

This Laravel package allows you to send emails securely using Gmail OAuth2 credentials, eliminating the need to store sensitive information like username and password in your application configuration.

Support us

This package is actively maintained and free to use. If you find it helpful, consider giving back by:

  • Reporting any issues or suggesting improvements through GitHub issues.
  • Contributing code or documentation changes via pull requests.
  • Leaving a star on the repository to show your appreciation. Your support helps keep this project alive and thriving!
  • Supporting me on Ko-fi

ko-fi

Installation

You can install the package via composer:

For PHP 8 and Laravel 9:

composer require iagofelicio/laravel-gmail-oauth2

For PHP 7 and Laravel 7/8:

composer require iagofelicio/laravel-gmail-oauth2:1.0.4

Gmail Credentials

To obtain a Gmail OAuth2 refresh token, you can refer to the instructions provided by the PHPMailer package on Github https://github.com/PHPMailer.

For detailed instructions on generating a Gmail OAuth2 refresh token, we recommend following the excellent tutorial provided by Coding Yet https://www.codingyet.com/how-to-use-phpmailer-with-xoauth2/.

This tutorial walks you through the process step-by-step, ensuring a smooth setup for your secure email sending.

Usage

(Step 1) For PHP 7 and Laravel 7/8:

Edit config/mail.php adding the following line:

return [

    'driver' => 'gmail',
    
    // Default code ...
];

(Step 1) For PHP 8 and Laravel 9:

Edit config/mail.php adding the following mailer:

return [

    'mailers' => [
        
        // Default code ...

        'gmail' => [
            'transport' => 'gmail',
        ],
    ]    
];

Edit the MAIL_MAILER in .env file:

MAIL_MAILER=gmail

(Step 2) For Laravel 7, 8 and 9:

Add your Gmail credentials in .env file:

GMAIL_API_CLIENT_ID="your-api-client-id"
GMAIL_API_CLIENT_SECRET="your-api-client-secret"
GMAIL_API_CLIENT_REFRESH_TOKEN="your-api-client-refresh-token"
GMAIL_API_CLIENT_MAIL="your-api-client-email"

# Suggested default settings to include
MAIL_FROM_ADDRESS="from@mail.com"
MAIL_FROM_NAME="${APP_NAME}"

Testing

Pending development.

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.


  Files folder image Files  
File Role Description
Files folder imagesrc (2 directories)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageProviders (1 file)
Files folder imageTransport (1 file)

  Files folder image Files  /  src  /  Providers  
File Role Description
  Plain text file GmailServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Transport  
File Role Description
  Plain text file GmailTransport.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:31
This week:1
All time:11,039
This week:69Up