纳瓦兹92/paubox-test

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

v3.0.0 2022-04-25 09:55 UTC

This package is auto-updated.

Last update: 2024-09-27 13:37:49 UTC


README

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

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标准的不含个人健康信息的邮件,即使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。