jornatf / msgraph-mailer
一个用于使用 Microsoft Graph API 发送电子邮件的 Laravel 扩展包。
v2.0.1
2023-04-22 15:59 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
一个用于使用 Microsoft Graph API 发送电子邮件的 Laravel 扩展包。
如果您喜欢这个扩展包,可以为我买杯咖啡 ☕️
安装
通过 composer
composer require jornatf/msgraph-mailer
先决条件
在 .env 文件中添加您的 Microsoft Graph 凭据
MSGRAPH_CLIENT_ID=your_client_id
MSGRAPH_SECRET_ID=your_secret_id
MSGRAPH_TENANT_ID=your_tenant_id
用法
示例
本示例展示了如何使用基本方法来发送电子邮件。
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; class PostController extends Controller { public function sendMail() { try { $msgraph = MsGraphMailer::mail('your@mailbox.com') ->to(['John Doe:john.doe@example.com', 'other@example.com', $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
变更日志
有关最近变更的更多信息,请参阅变更日志。
贡献
请自由地为此项目做出贡献,以添加新功能或修复错误 👍
鸣谢
许可证
MIT 许可证 (MIT)。
有关更多信息,请参阅许可证文件。