hanfrey/sparkpost-bundle

此扩展包提供与Sparkpost API库的集成,允许您在Symfony项目中与Sparkpost API交互

安装数: 7,851

依赖项: 0

建议者: 0

安全: 0

星标: 9

关注者: 1

分支: 4

开放问题: 1

类型:symfony-bundle

dev-master 2017-05-18 17:44 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:09:23 UTC


README

用于在symfony中使用Sparkpost的扩展包

安装

步骤1) 获取扩展包

composer require hanfrey/sparkpost-bundle

步骤2) 注册扩展包

要开始使用扩展包,请在您的Kernel中注册它。

<?php
// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Hanfrey\SparkpostBundle\HanfreySparkpostBundle(),
        // ...
    );
}

步骤3) 配置默认API令牌(必填)

以下是一个示例

# app/config/config.yml
hanfrey_sparkpost:
    api_token: 1212334ba # replace with your own

步骤4) 控制器中的示例用法

$sparky= $this->get("hanfrey_sparkpost.api_client");

try {
    // Build your email and send it!
    $results = $sparky->transmission->send([
        'from'=>'From Envelope <from@sparkpostbox.com>',
        'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
        'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
        'substitutionData'=>['name'=>'YOUR FIRST NAME'],
        'subject'=>'First Mailing From PHP',
        'recipients'=>[
            [
                'address'=>[
                    'name'=>'YOUR FULL NAME',
                    'email'=>'YOUR EMAIL ADDRESS'
                ]
            ]
        ]
    ]);
    echo 'Woohoo! You just sent your first mailing!';
} catch (\Exception $err) {
    echo 'Whoops! Something went wrong';
    var_dump($err);
}

文档

有关如何访问每个API方法的详细文档可以在此扩展包集成的包的文档中找到: Sparkpost API库