Stampie 开源项目教程
StampieLibrary for using online Email providers项目地址:https://gitcode.com/gh_mirrors/st/Stampie
1. 项目的目录结构及介绍
Stampie 项目的目录结构如下:
Stampie/
├── composer.json
├── composer.lock
├── docs/
│ └── index.md
├── examples/
│ └── example.php
├── LICENSE
├── README.md
├── src/
│ ├── Adapter/
│ │ ├── HttpAdapterInterface.php
│ │ └── ...
│ ├── Exception/
│ │ └── ExceptionInterface.php
│ ├── Mailer/
│ │ ├── MailerInterface.php
│ │ └── ...
│ ├── Message/
│ │ ├── MessageInterface.php
│ │ └── ...
│ └── Stampie.php
├── tests/
│ ├── Adapter/
│ │ └── ...
│ ├── Mailer/
│ │ └── ...
│ └── bootstrap.php
└── vendor/
目录结构介绍
composer.json
和composer.lock
:Composer 依赖管理文件。docs/
:项目文档目录,包含index.md
文档。examples/
:示例代码目录,包含example.php
示例文件。LICENSE
:项目许可证文件。README.md
:项目说明文档。src/
:源代码目录,包含Adapter
、Exception
、Mailer
和Message
等子目录。tests/
:测试代码目录,包含Adapter
和Mailer
等子目录。vendor/
:Composer 自动生成的第三方依赖库目录。
2. 项目的启动文件介绍
Stampie 项目的启动文件主要是 examples/example.php
,该文件展示了如何使用 Stampie 发送邮件。
启动文件内容
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Stampie\Mailer\Postmark;
use Stampie\Message\MarkdownMessage;
use Stampie\Adapter\BuzzAdapter;
use Buzz\Client\Curl;
$client = new Curl();
$adapter = new BuzzAdapter($client);
$mailer = new Postmark($adapter, 'your-postmark-api-token');
$message = new MarkdownMessage('sender@example.com', 'recipient@example.com', 'Subject', 'Content');
$mailer->send($message);
启动文件介绍
- 引入 Composer 自动加载文件。
- 使用
Stampie\Mailer\Postmark
类创建邮件发送器。 - 使用
Stampie\Message\MarkdownMessage
类创建邮件消息。 - 使用
Stampie\Adapter\BuzzAdapter
类创建 HTTP 适配器。 - 使用
Buzz\Client\Curl
类创建 HTTP 客户端。 - 调用
send
方法发送邮件。
3. 项目的配置文件介绍
Stampie 项目的配置文件主要是 composer.json
,该文件定义了项目的依赖和其他配置信息。
配置文件内容
{
"name": "stampie/stampie",
"description": "Library for using online Email providers",
"keywords": ["email", "postmark", "sendgrid", "mailgun", "mandrill"],
"homepage": "https://github.com/Stampie/Stampie",
"license": "MIT",
"authors": [
{
"name": "Henrik Bjornskov",
"email": "henrik@bjrnskov.dk"
}
],
"require": {
"php": ">=5.5.9",
"symfony/http-foundation": "^2.7|^3.0|^4.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",
"symfony/phpunit-bridge": "^2.7|^3.0|^4.0",
"symfony/browser-kit": "^2.7|^3.0|^4.0",
"symfony/css-selector": "^2.7|^3.0|^4.0",
"symfony/dom-crawler": "^2
StampieLibrary for using online Email providers项目地址:https://gitcode.com/gh_mirrors/st/Stampie