angelpm9506/sendgritpapiinterface

与sengrid API通信的项目

1.2.0 2024-08-20 19:10 UTC

This package is auto-updated.

Last update: 2024-09-20 19:35:25 UTC


README

NDD_send_connect 是一个用于与 NDDInfosystems 的 Send API 通信的 PHP 库。它允许您通过 API key 或 token 向特定 URL 发送电子邮件。

要求

  • PHP 5.6 或更高版本
  • cURL

安装

您可以使用 Composer 安装此库。首先,确保您已安装 Composer,然后执行以下命令:

composer require angelpm9506/sendgridapiinterface

初始化

要使用此库,您必须首先使用您的 API key 初始化 NDD_send_connect 类,如果您使用的是 PHP 8.0 或更高版本。

require 'vendor/autoload.php';

use NDD_send_connect\NDD_send_connect;

$apikey = 'tu-api-key || Token';
$urlBase = "https://baseurle.test"; // url a que se comunicara
$isToken = false; // si es un token en lugar deuna apikey lo que se esta implementando
$sendConnect = new NDD_send_connect($apikey, $urlBase, isToken);

如果您使用的是低于 8.0 的 PHP 版本,您必须使用 NDD_send_connect_php56 类,因为它实现了低于 8.0 的 PHP 版本所需的方法。

require 'vendor/autoload.php';

use NDD_send_connect_php56\NDD_send_connect_php56;

$apikey = 'tu-api-key || Token';
$urlBase = "https://baseurle.test"; // url a la que se comunicara
$isToken = false; // si es un token se coloca en true 
$sendConnect = new NDD_send_connect_php56($apikey, $urlBase, isToken);

发送电子邮件

您可以使用 send_emailsend_email_token 方法发送电子邮件。

$from = 'correoOrigen@example.com';
$to = 'destinatario@example.com';
$cc = 'concopiaa@example.com'; // opcional y puede ser null
$bcc = 'concopiaoculta@example.com'; // opcional y puede ser null
$subject = 'Asunto del correo';
$html = '<p>Contenido del correo en HTML</p>';
$text = 'Contenido del correo en texto plano';

$responseByApikey = $sendgrid->send_email($from, $to, $subject, $cc, $bcc, $html, $text);
$responseByToken = $sendgrid->send_email_token($from, $to, $subject, $cc, $bcc, $html, $text);

print_r($responseByApikey);
print_r($responseByToken);

根据情况,您需要指定是否使用 apikey 或 token,因为它们之间存在细微差别。

可用方法

set_url($url):设置新的基本 URL。

set_defaultUrl():重置默认基本 URL。

get_url():获取当前基本 URL。

set_apikey($apikey, $isToken = false):设置新的 API key。

send_email($from, $to, $subject, $cc = null, $bcc = null, $html = null, $text = null):使用 API key 发送电子邮件。

send_email_token($from, $to, $subject, $cc = null, $bcc = null, $html = null, $text = null):使用 token 发送电子邮件。