paubox / paubox-php
Paubox 交易型电子邮件 API 的 PHP 包
Requires
- nategood/httpful: *
- vlucas/phpdotenv: 3.4.0
Requires (Dev)
- phpunit/phpunit: ^5.7.9
This package is not auto-updated.
Last update: 2024-09-20 11:03:05 UTC
README
Paubox PHP
这是 Paubox 电子邮件 API 的官方 PHP 封装Paubox 电子邮件 API。
Paubox 电子邮件 API 允许您的应用程序通过 Paubox 发送安全、符合 HIPAA 标准的电子邮件,并跟踪投递和打开情况。API 封装还允许您构建和发送消息。
目录
安装
使用 composer
$ composer require paubox/paubox-php
获取 Paubox API 凭证
您需要一个 Paubox 账户。您可以在这里注册。
一旦您有账户,请按照 Rest API 控制台上的说明进行操作,以验证域名所有权并生成 API 凭证。
配置 API 凭证
在您的环境文件中包含 API 凭证。
$ echo "export PAUBOX_API_KEY='YOUR_API_KEY'" > .env $ echo "export PAUBOX_API_USER='YOUR_ENDPOINT_NAME'" >> .env $ source .env $ echo ".env" >> .gitignore
使用
要发送电子邮件,请准备一个消息对象,并调用 Paubox 的 sendMessage 方法。
发送消息
<?php require_once __DIR__ . '/vendor/autoload.php'; $dotenv = Dotenv\Dotenv::create(__DIR__); $dotenv->load(); $paubox = new Paubox\Paubox(); $message = new Paubox\Mail\Message(); $content = new Paubox\Mail\Content(); $content->setPlainText("Hello World"); $header = new Paubox\Mail\Header(); $header->setSubject("Testing!"); $header->setFrom("sender@domain.com"); $recipients = array(); array_push($recipients,'recipient@example.com'); $message->setHeader($header); $message->setContent($content); $message->setRecipients($recipients); $sendMessageResponse = new Paubox\Mail\SendMessageResponse(); $sendMessageResponse = $paubox->sendMessage($message); print_r($sendMessageResponse);
允许非 TLS 消息投递
如果您想发送不需要符合 HIPAA 标准的非 PHI 邮件,您可以在 TLS 连接不可用的情况下允许消息投递。
这意味着当遇到非 TLS 连接时,消息不会被转换为安全门户消息。要允许非 TLS 消息投递,请在消息对象上调用 setAllowNonTLS(true) 方法。
<?php require_once __DIR__ . '/vendor/autoload.php'; $dotenv = Dotenv\Dotenv::create(__DIR__); $dotenv->load(); $paubox = new Paubox\Paubox(); $message = new Paubox\Mail\Message(); $content = new Paubox\Mail\Content(); $content->setPlainText("Hello World"); $header = new Paubox\Mail\Header(); $header->setSubject("Testing!"); $header->setFrom("sender@domain.com"); $recipients = array(); array_push($recipients,'recipient@example.com'); $message->setHeader($header); $message->setContent($content); $message->setRecipients($recipients); $message->setAllowNonTLS(true); $sendMessageResponse = new Paubox\Mail\SendMessageResponse(); $sendMessageResponse = $paubox->sendMessage($message); print_r($sendMessageResponse);
强制安全通知
Paubox 安全通知提供了额外的安全层,尤其是当与组织对消息接收者使用双因素认证读取消息的要求相结合时(此设置在 Paubox 管理面板中的组织管理员可用)。
接收者将收到一封通知电子邮件,告知他们在 Paubox 中有新消息,而不是接收包含消息内容的电子邮件。
<?php require_once __DIR__ . '/vendor/autoload.php'; $dotenv = Dotenv\Dotenv::create(__DIR__); $dotenv->load(); $paubox = new Paubox\Paubox(); $message = new Paubox\Mail\Message(); $content = new Paubox\Mail\Content(); $content->setPlainText("Hello World"); $header = new Paubox\Mail\Header(); $header->setSubject("Testing!"); $header->setFrom("sender@domain.com"); $recipients = array(); array_push($recipients,'recipient@example.com'); $message->setHeader($header); $message->setContent($content); $message->setRecipients($recipients); $message->setForceSecureNotification("true"); $sendMessageResponse = new Paubox\Mail\SendMessageResponse(); $sendMessageResponse = $paubox->sendMessage($message); print_r($sendMessageResponse);
添加附件和额外的头部信息
<?php require_once __DIR__ . '/vendor/autoload.php'; $dotenv = Dotenv\Dotenv::create(__DIR__); $dotenv->load(); $paubox = new Paubox\Paubox(); $message = new Paubox\Mail\Message(); $content = new Paubox\Mail\Content(); $content->setPlainText("Hello World"); $content->setHtmlText("<html><head></head><body>Hello World</body></html>"); $header = new Paubox\Mail\Header(); $header->setSubject("Testing!"); $header->setFrom("sender@domain.com"); $header->setReplyTo("reply_to@domain.com"); $firstAttachment = new Paubox\Mail\Attachment(); $firstAttachment->setFileName("hello_world.txt"); $firstAttachment->setContentType("text/plain"); $firstAttachment->setContent("SGVsbG8gV29ybGQh\n"); $secondAttachment = new Paubox\Mail\Attachment(); $secondAttachment->setFileName("hello_world2.txt"); $secondAttachment->setContentType("text/plain"); $secondAttachment->setContent("SGVsbG8gV29ybGQh\n"); $attachments = array(); array_push($attachments,$firstAttachment); array_push($attachments,$secondAttachment); $recipients = array(); array_push($recipients,'recipient@example.com'); $bcc = array(); array_push($bcc, 'recipient2@example.com'); $cc = array(); array_push($cc, 'recipientcc@example.com'); $message->setHeader($header); $message->setContent($content); $message->setAttachments($attachments); $message->setRecipients($recipients); $message->setBcc($bcc); $sendMessageResponse = new Paubox\Mail\SendMessageResponse(); $sendMessageResponse = $paubox->sendMessage($message); print_r($sendMessageResponse);
检查电子邮件处理情况
消息的 SOURCE_TRACKING_ID 返回在 sendMessage 方法的响应中。要检查任何电子邮件的状态,请使用其源跟踪 ID 并调用 Paubox 的 getEmailDisposition 方法。
<?php require_once __DIR__ . '/vendor/autoload.php'; $dotenv = Dotenv\Dotenv::create(__DIR__); $dotenv->load(); $paubox = new Paubox\Paubox(); $resp = $paubox->getEmailDisposition('SOURCE_TRACKING_ID'); print_r($resp);
贡献
欢迎在 GitHub 上提交错误报告和拉取请求 https://github.com/paubox/paubox-php。
许可证
遵循 Apache 许可证 2.0 版(“许可证”);除非遵守许可证规定或书面同意,否则不得使用此文件。您可以在 https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证副本。
除非适用法律要求或书面同意,否则根据许可证分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言管理权限和限制,请参阅许可证。
版权
版权所有 © 2021,Paubox,Inc。