PHP code example of maize-tech / laravel-msgraph-mailer

1. Go to this page and download the library: Download maize-tech/laravel-msgraph-mailer 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/ */

    

maize-tech / laravel-msgraph-mailer example snippets


'mailers' => [
    // ... other mailers

    'microsoft-graph' => [
        'transport' => 'microsoft-graph',
        'tenant_id' => env('MICROSOFT_GRAPH_TENANT_ID'),
        'client_id' => env('MICROSOFT_GRAPH_CLIENT_ID'),
        'client_secret' => env('MICROSOFT_GRAPH_CLIENT_SECRET'),
    ],
],

use Illuminate\Support\Facades\Mail;

Mail::raw('Hello from Microsoft Graph!', function ($message) {
    $message->to('[email protected]')
            ->subject('Test Email');
});

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

Mail::to('[email protected]')->send(new WelcomeEmail($user));

use Illuminate\Support\Facades\Mail;

Mail::send('emails.welcome', ['user' => $user], function ($message) use ($user) {
    $message->to($user->email)
            ->subject('Welcome!')
            ->attach('/path/to/file.pdf');
});

app('mail.microsoft-graph.token-provider')->clearToken();