sendpost/sendpost_php_sdk

电子邮件API和SMTP中继不仅用于发送和测量电子邮件发送,还用于警报和优化。我们为您提供所需工具、专业知识和支持,以确保您的客户收件箱能够准时可靠地接收电子邮件。

1.2.2 2023-09-29 06:12 UTC

This package is not auto-updated.

Last update: 2024-09-17 16:09:40 UTC


README

电子邮件API和SMTP中继不仅用于发送和测量电子邮件发送,还用于警报和优化。我们为您提供所需工具、专业知识和支持,以确保您的客户收件箱能够准时可靠地接收电子邮件。

安装和用法

需求

PHP 7.4及更高版本。也应与PHP 8.0兼容。

Composer

要通过Composer安装绑定,请在composer.json中添加以下内容

{
  "require": {
    "sendpost/sendpost_php_sdk": "^1.0.0"
  }
}

然后运行composer install

手动安装

下载文件并包含autoload.php

<?php
require_once('/path/to/sendpost/vendor/autoload.php');

入门

请遵循安装过程,然后运行以下命令

  require_once(__DIR__ . '/vendor/autoload.php');
  $client = new GuzzleHttp\Client();

  $apiInstance = new sendpost\api\EmailApi($client);

  $x_sub_account_api_key = 'your_api_key'; // string | Sub-Account API Key
  $email_message = new \sendpost\model\EmailMessage(); 
  $email_message->setSubject('Hello World');
  $email_message->setHtmlBody('<strong>it works!</strong>');
  $email_message->setIppool('PiedPiper');
  $from = new \sendpost\model\From();
  $from->setEmail('richard@piedpiper.com');

  $to = new \sendpost\model\To();
  $to->setEmail('gavin@hooli.com');
  $email_message->setTo(array($to));
  $email_message->setFrom($from);

  try {
      $result = $apiInstance->sendEmail($x_sub_account_api_key, $email_message);
      print_r($result);
  } catch (Exception $e) {
      echo 'Exception when calling EmailApi->sendEmail: ', $e->getMessage(), PHP_EOL;
  }

带有cc、bcc和模板的示例

  require_once(__DIR__ . '/vendor/autoload.php');
  $client = new GuzzleHttp\Client();

  $apiInstance = new sendpost\api\EmailApi($client);

  $x_sub_account_api_key = 'your_api_key'; // string | Sub-Account API Key
  $email_message = new \sendpost\model\EmailMessage(); 
  $email_message->setSubject('Hello World');
  $email_message->setHtmlBody('<strong>it works!</strong>');
  $email_message->setIppool('PiedPiper');
  $from = new \sendpost\model\From();
  $from->setEmail('richard@piedpiper.com');

  $cc = new \sendpost\model\CopyTo();
  $cc->setEmail('dinesh@bachmanity.com');
  $to->setCc(array($cc));
  $bcc = new \sendpost\model\CopyTo();
  $bcc->setEmail('jian@bachmanity.com');
  $to->setBcc(array($bcc));

  $email_message->setTemplate('Welcome Mail');

  $to = new \sendpost\model\To();
  $to->setEmail('gavin@hooli.com');
  $email_message->setTo(array($to));
  $email_message->setFrom($from);

  try {
      $result = $apiInstance->sendEmailWithTemplate($x_sub_account_api_key, $email_message);
      print_r($result);
  } catch (Exception $e) {
      echo 'Exception when calling EmailApi->sendEmailWithTemplate: ', $e->getMessage(), PHP_EOL;
  }

抑制

创建抑制

  require_once(__DIR__ . '/vendor/autoload.php');
  $client = new GuzzleHttp\Client();

  $apiInstance = new sendpost\api\SuppressionApi($client);

  $x_sub_account_api_key = 'your_api_key'; 

  $r_suppression = new \sendpost\model\RSuppression();
  $suppression_email = new \sendpost\model\SuppressionEmail();
  $suppression_email->setEmail('richard@piedpiper_fake.com');

  $r_suppression->setHardBounce(array($suppression_email));

  // fields are optional, but you have to send at least one of them.

  // $r_suppression->setManual(array($suppression_email));
  // $r_suppression->setSpamComplaint(array($suppression_email));
  // $r_suppression->setUnsubscribe(array($suppression_email));

  try {
      $result = $apiInstance->createSuppressions($x_sub_account_api_key, $r_suppression);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->createSuppressions: ', $e->getMessage(), PHP_EOL;
  }

获取抑制

  require_once(__DIR__ . '/vendor/autoload.php');
  $client = new GuzzleHttp\Client();

  $apiInstance = new sendpost\api\SuppressionApi($client);

  $x_sub_account_api_key = 'your_api_key'; 

  $offset = 0;
  $limit = 10;
  $search = null;
  $from = '2023-06-07';
  $to = '2023-08-02';

  try {
      $result = $apiInstance->getSuppressions($x_sub_account_api_key, $offset, $limit, $search, $from, $to);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->getSuppressions: ', $e->getMessage(), PHP_EOL;
  }

删除抑制

  require_once(__DIR__ . '/vendor/autoload.php');
  $client = new GuzzleHttp\Client();

  $apiInstance = new sendpost\api\SuppressionApi($client);

  $x_sub_account_api_key = 'your_api_key'; 

  $rd_suppression = new \sendpost\model\RDSuppression();
  $suppression_email = new \sendpost\model\SuppressionEmail();
  $suppression_email->setEmail('richard@piedpiper_fake.com');

  $rd_suppression->setSuppressions(array($suppression_email));

  try {
      $result = $apiInstance->deleteSuppression($x_sub_account_api_key, $rd_suppression);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->deleteSuppression: ', $e->getMessage(), PHP_EOL;
  }

计数抑制

  require_once(__DIR__ . '/vendor/autoload.php');
  $client = new GuzzleHttp\Client();

  $apiInstance = new sendpost\api\SuppressionApi($client);

  $x_sub_account_api_key = 'your_api_key'; 

  $from = '2023-06-07';
  $to = '2023-08-02';

  try {
      $result = $apiInstance->count($x_sub_account_api_key, $from, $to);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->count: ', $e->getMessage(), PHP_EOL;
  }

API端点

所有URI均相对于https://api.sendpost.io/api/v1

模型

授权

端点不需要授权。

测试

要运行测试,请使用

composer install
vendor/bin/phpunit

作者

dev@sendpost.io