omarpre/paubox

Paubox 事务性电子邮件 API 的 PHP 包(原 paubox-php SDK 的分支)

v4.0.0 2023-10-19 14:19 UTC

This package is not auto-updated.

Last update: 2024-09-19 18:52:28 UTC


README

这是 Paubox php SDK 的分支,以使其与 Laravel 9 版本兼容

Paubox

Paubox PHP

这是 Paubox 电子邮件 API 的官方 PHP 包装器。

Paubox 电子邮件 API 允许您的应用程序通过 Paubox 发送安全、符合 HIPAA 标准的电子邮件,并跟踪投递和打开情况。API 包装器还允许您构建和发送消息。

目录

安装

使用 composer

$ composer require omarpre/paubox

获取 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/omarpre/paubox

许可

根据 Apache 许可证 2.0 版(“许可证”);除非根据适用法律或书面同意,否则不得使用此文件,除非符合许可证。您可以在 https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证副本。

除非适用法律要求或书面同意,否则根据许可证分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言管辖权限和限制,请参阅许可证。

版权

版权所有 © 2021,Paubox,Inc。