amply/amply-php

v0.0.1 2020-12-31 00:07 UTC

This package is not auto-updated.

Last update: 2024-09-20 15:00:49 UTC


README

这是 Amply PHP SDK,它集成了 v1 API

目录

安装

先决条件

访问令牌

Amply UI 获取您的访问令牌。

安装包

将 Amply 添加到您的 composer.json 文件中。如果您没有使用 Composer,我们强烈建议您使用它。它是管理 PHP 应用程序中依赖关系的绝佳方式。

{
  "require": {
    "amply/amply-php": "*"
  }
}

替代方案:从仓库安装

如果您没有使用 Composer,只需从 Github 仓库下载并检出您想使用的版本。

git clone https://github.com/sendamply/amply-php.git
git checkout VERSION

域名验证

通过仪表板上的 已验证域名 选项卡添加您想要发送 from 的域名。

您尝试从未经验证的域名发送的任何电子邮件都将被拒绝。一旦验证,Amply 立即开始预热您的域名和 IP 声誉。这个过程大约需要一周时间,才能达到最大可投递性。

快速开始

以下是最小化发送简单电子邮件所需的代码。使用此示例,并修改 tofrom 变量

// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment the next line if you're not using a dependency loader (such as Composer), replacing <PATH TO> with the path to the amply-php.php file
// require_once '<PATH TO>/amply-php.php';

$amply = new Amply(getenv('AMPLY_ACCESS_TOKEN'));

try {
    $amply->email->create(array(
        'to' => 'test@example.com',
        'from' => 'test@verifieddomain.com',
        'subject' => 'My first Amply email!',
        'text' => 'This is easy',
        'html' => '<strong>and fun :)</strong>'
    ));
}
catch (\Amply\Exceptions\APIException $e) {
    echo "Generic API error\n";
    echo "$e->code\n";
    echo "$e->text\n";
}
catch (\Amply\Exceptions\ValidationException $e) {
    echo "Invalid input\n";
    print_r($e->errors);
}
catch (\Amply\Exceptions\ResourceNotFoundException $e) {
    echo "Missing resource\n";
    print_r($e->errors);
}

执行此代码后,您应该在收件人的收件箱中看到一封电子邮件。您可以从 搜索SQL用户 页面检查您电子邮件的状态。

方法

email

示例

$amply.email.create(array(
    'to' => "example@test.com",
    'cc' => array('name' => 'Billy', 'email' => 'Smith'),
    'from' => 'From <example@verifieddomain.com>',
    'text' => 'Text part',
    'html' => 'HTML part',
    'content' => array(
        array(
            'type' => 'text/testing',
            'value' => 'Test!',
        ),
    ),
    'subject' => 'A new email!',
    'replyTo' => 'Reply To <test@example.com>',
    'template' => 'faecb75b-371e-4062-89d5-372b8ff0effd',
    'dynamicTemplateData' => array('name' => 'Jimmy'),
    'unsubscribeGroupUuid' => '5ac48b43-6e7e-4c51-817d-f81ea0a09816',
    'ipOrPoolUuid' => '2e378fc9-3e23-4853-bccb-2990fda83ca9',
    'attachments' => array(
        array(
            'content' => 'dGVzdA==',
            'filename' => 'test.txt',
        ),
    ),
    'headers' => array('X-Testing' => 'Test'),
    'categories' => array('Test'),
    'clicktracking' => true,
    'substitutions' => array('sub1' => 'replacement1')
));