PHP code example of eibs / laravel-gmail-mailbox

1. Go to this page and download the library: Download eibs/laravel-gmail-mailbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eibs / laravel-gmail-mailbox example snippets


   'middleware' => ['web', 'auth'],
   

'middleware' => ['web', 'auth:admin', 'role:super-admin'],

'layout' => env('GMAIL_MAILBOX_LAYOUT', 'layouts.app'),

use Queen\GmailMailbox\Services\GmailService;

class MailboxController extends Controller
{
    public function index(GmailService $gmailService)
    {
        // 1. Check if Gmail is connected
        if (!$gmailService->isAuthenticated()) {
            return redirect()->route('gmail.auth');
        }

        // 2. Get active and connected accounts
        $activeAccount = $gmailService->getActiveAccount(); // GoogleToken model
        $allAccounts   = $gmailService->getAllAccounts();

        // 3. Switch active account programmatically
        $gmailService->switchAccount($accountId);

        // 4. Send an email from active account
        $result = $gmailService->sendEmail(
            to: '[email protected]',
            subject: 'Project Update Notification',
            body: '<h2>Hello!</h2><p>Your project update is ready for review.</p>',
            attachments: [
                ['path' => storage_path('app/invoice.pdf'), 'name' => 'Invoice.pdf']
            ]
        );

        return response()->json(['success' => true, 'message' => 'Email sent!']);
    }
}
bash
php artisan migrate
bash
php artisan vendor:publish --tag=gmail-mailbox-migrations
bash
php artisan vendor:publish --tag=gmail-mailbox-config
bash
   php artisan vendor:publish --tag=gmail-mailbox-config
   
bash
php artisan vendor:publish --tag=gmail-mailbox-views