wildbit/swiftmailer-postmark
Composer 安装命令:
composer require wildbit/swiftmailer-postmark
包简介
A Swiftmailer Transport for Postmark.
README 文档
README
An official Swiftmailer Transport for Postmark.
Send mail through Postmark from your favorite PHP frameworks!
Usage
1. Include this package in your project:
composer require wildbit/swiftmailer-postmark
2. Use the transport to send a message:
<?php //import the transport from the standard composer directory: require_once('./vendor/autoload.php'); $transport = new \Postmark\Transport('<SERVER_TOKEN>'); $mailer = new Swift_Mailer($transport); //Instantiate the message you want to send. $message = (new Swift_Message('Hello from Postmark!')) ->setFrom(['john@example.com' => 'John Doe']) ->setTo(['jane@example.com']) ->setBody('<b>A really important message from our sponsors.</b>', 'text/html') ->addPart('Another important message from our sponsors.','text/plain'); //Add some attachment data: $attachmentData = 'Some attachment data.'; $attachment = new Swift_Attachment($attachmentData, 'my-file.txt', 'application/octet-stream'); $message->attach($attachment); //Send the message! $mailer->send($message); ?>
3. Throw exceptions on Postmark api errors:
$transport = new \Postmark\Transport('<SERVER_TOKEN>'); $transport->registerPlugin(new \Postmark\ThrowExceptionOnFailurePlugin()); $message = new Swift_Message('Hello from Postmark!'); $mailer->send($message); // Exception is throw when response !== 200
4. Use default headers:
You can set default headers at Transport-level, to be set on every message, unless overwritten.
$defaultHeaders = ['X-PM-Tag' => 'my-tag']; $transport = new \Postmark\Transport('<SERVER_TOKEN>', $defaultHeaders); $message = new Swift_Message('Hello from Postmark!'); // Overwriting default headers $message->getHeaders()->addTextHeader('X-PM-Tag', 'custom-tag');
5. Setting the Message Stream:
By default, the "outbound" transactional stream will be used when sending messages.
// Change the default stream for every message via Default Headers $transport = new \Postmark\Transport('<SERVER_TOKEN>', ['X-PM-Message-Stream' => 'your-custom-stream']); $message = new Swift_Message('Hello from Postmark!'); // Overwrite the default stream for a specific message by setting the header $message->getHeaders()->addTextHeader('X-PM-Message-Stream', 'another-stream');
6. Getting the Postmark Message ID after sending
After sending the mail to Postmark, it is possible to get the Postmark ID.
$transport = new \Postmark\Transport('<SERVER_TOKEN>', $defaultHeaders); $mailer = new Swift_Mailer($transport); $message = new Swift_Message('Hello from Postmark!'); $mailer->send($message); $postmarkID = $message->getHeaders()->get('X-PM-Message-Id')->getValue();
Releasing a new version
Swiftmailer Transport uses packagist. To publish a new version, simply create a new release on GitHub tagged with the version number.
Notes:
- The Transport uses the Postmark API internally to send mail, via the /email endpoint. Other sending features such as Batch sending or sending via Templates are currently not supported by this library.
wildbit/swiftmailer-postmark 适用场景与选型建议
wildbit/swiftmailer-postmark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.86M 次下载、GitHub Stars 达 54, 最近一次更新时间为 2015 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wildbit/swiftmailer-postmark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wildbit/swiftmailer-postmark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.86M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 55
- 点击次数: 24
- 依赖项目数: 9
- 推荐数: 20
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-27