stephenfarrell/postmark-bundle

Miguel Perez不再维护的代码的微小更新,源自 https://github.com/miguel250/PostmarkBundle,以支持 Symfony 3 兼容性。显然,所有关于这项工作的赞誉、认可和感谢都应该归功于他。

安装数: 4,741

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 12

类型:symfony-bundle

v0.0.6 2013-09-12 14:29 UTC

This package is not auto-updated.

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


README

Symfony 3 对 Postmark API 的扩展 构建状态

这是对 Miguel Perez 的不再维护的代码的极其微小更新,源自 https://github.com/miguel250/PostmarkBundle,以支持 Symfony 3 兼容性。显然,所有关于这项工作的赞誉、认可和感谢都应该归功于他。

安装

使用 Composer 将 PostmarkBundle 添加到您的 composer.json 中

{
    "require": {
        "stephenfarrell/postmark-bundle": "*"
    }
}
$ php composer.phar update mlpz/postmark-bundle

使用子模块

git submodule add https://github.com/miguel250/PostmarkBundle.git vendor/bundles/MZ/PostmarkBundle
git submodule add https://github.com/kriswallsmith/Buzz.git  vendor/buzz

添加 MZ 命名空间到自动加载器 当使用 Composer 时,您可以跳过此步骤

<?php
   // app/autoload.php
   $loader->registerNamespaces(array(
    // ...
    'MZ'               => __DIR__.'/../vendor/bundles',
    'Buzz'             => __DIR__.'/../vendor/buzz/lib',
  ));

将 PostmarkBundle 添加到您的应用程序内核中

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new MZ\PostmarkBundle\MZPostmarkBundle(),
    );
}

在 config.yml 中启用 Postmark

mz_postmark:
    api_key: API KEY
    from_email: info@my-app.com
    from_name: My App, Inc
    use_ssl: true
    timeout: 5

使用方法

消息服务

<?php
$message  = $this->get('postmark.message');
$message->addTo('test@gmail.com', 'Test Test');
$message->setSubject('subject');
$message->setHTMLMessage('<b>email body</b>');
$message->addAttachment(new Symfony\Component\HttpFoundation\File\File(__FILE__));
$response = $message->send();

$message->addTo('test2@gmail.com', 'Test2 Test');
$message->setSubject('subject2');
$message->setHTMLMessage('<b>email body</b>');
$message->addAttachment(new Symfony\Component\HttpFoundation\File\File(__FILE__), 'usethisfilename.php', 'text/plain');
$response = $message->send();
?>

批量发送

<?php
$message  = $this->get('postmark.message');
$message->addTo('test@gmail.com', 'Test Test');
$message->setSubject('subject');
$message->setHTMLMessage('<b>email body</b>');
$message->queue(); // Queue the message instead of sending it directly

$message->addTo('test2@gmail.com', 'Test2 Test');
$message->setSubject('subject2');
$message->setHTMLMessage('<b>email body</b>');
$responses = $message->send(); // Send both messages, note that you'll get an array of json responses instead of just the json response
?>