A Laravel Package to send emails with Microsoft Graph API.
If you like this package you can Buy me a Coffee ☕️
composer require jornatf/msgraph-mailer
Add your Microsoft Graph credentials in the .env
file:
MSGRAPH_CLIENT_ID=your_client_id
MSGRAPH_SECRET_ID=your_secret_id
MSGRAPH_TENANT_ID=your_tenant_id
This example shows you how to use the basic methods required to send an email.
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class PostController extends Controller
{
public function sendMail()
{
try {
$msgraph = MsGraphMailer::mail('[email protected]')
->to(['John Doe:[email protected]', '[email protected]', $otherRecipients])
->subject('A simple email')
->body('<h1>Send a simple email to one recipient.</h1>')
->send();
} catch (\Exception $e) {
return $e->getMessage();
}
return "Email sended!";
}
}
<?php
// First, instantiate response with your Msgraph mailbox (required):
$msgraph = MsGraphMailer::mail(string $mailbox);
// Add a main recipient(s), a subject and a content (required):
$msgraph->to(array $toRecipient);
$msgraph->subject(string $subject);
$msgraph->content(string $contentHTML);
// You can add Cc and/or bcc with the same way (optionally):
$msgraph->cc(array $ccRecipient);
$msgraph->bcc(array $bccRecipient);
// Optionally, you can add one or many attachments:
$msgraph->addAttachment(array $attachment = [
'name' => $filename,
'contentType' => $contentType,
'content' => $contentBytes
]);
// and repeat if you have many attachments.
// Last, send your mail:
$msgraph->send();
composer test
Please see CHANGELOG for more information on what has changed recently.
Feel free to contribute to this project to improve with new features or fix bugs 👍
The MIT License (MIT).
Please see License File for more information.