linyows / notionslot
Notionslot 将消息存储在 Notion 的数据库中,用于电子邮件通知。
v0.3.0
2022-08-06 07:43 UTC
Requires (Dev)
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2024-09-28 20:09:23 UTC
README
Notionslot 将消息存储在 Notion 的数据库中,用于电子邮件通知。它通常用于网站托管服务的联系表单。
用法
API 模式
use \Notionslot\Slot; $config = [ 'notion_token' => 'secret_**********************************', 'notion_db_id' => '123456aa-bc12-1234-5678-0987654321aa', 'site_domain' => 'foo.example', 'site_name' => 'My Foo', 'notify_to' => 'me@foo.example', 'reply_to' => 'hello@foo.example', 'mail_from' => 'noreply@foo.example', ]; $data = array_merge($_POST, ['ip' => $_SERVER['REMOTE_ADDR']]); echo Slot::api($config, $_SERVER, $data);
库模式
use \Notionslot\Slot; $config = [ 'notion_token' => 'secret_**********************************', 'notion_db_id' => '123456aa-bc12-1234-5678-0987654321aa', 'site_domain' => 'foo.example', 'site_name' => 'My Foo', 'notify_to' => 'me@foo.example', 'reply_to' => 'hello@foo.example', 'mail_from' => 'noreply@foo.example', ]; $data = array_merge($_POST, ['ip' => $_SERVER['REMOTE_ADDR']]); $res = [ 'ok' => true, 'errors' => [], ]; $slot = new Slot($config); if ($slot->sendHeader($_SERVER)->setData($data)->isValid()) { $notionRes = $slot->notify()->reply()->save(); } else { http_response_code(422); $res = [ 'ok' => false, 'errors' => $slot->errors(), ]; } echo json_encode($res);
安装
推荐通过 Composer 安装 Guzzle。
$ composer require linyows/notionslot
配置
请通过配置指定 notion token、网站域名、发件人、回复等。
自定义
默认的 Notion 数据库属性名称为 Full name(title)、Email address(email)、IP(rich_text)。您可以从设置中更改属性名称和类型。