PHPackages                             easyswoole/smtp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. easyswoole/smtp

ActiveLibrary

easyswoole/smtp
===============

EasySwoole mailer component

2.0.2(3y ago)914.7k↑63.6%7[5 issues](https://github.com/easy-swoole/smtp/issues)Apache-2.0PHPPHP &gt;=7.1.0

Since Feb 2Pushed 3y ago2 watchersCompare

[ Source](https://github.com/easy-swoole/smtp)[ Packagist](https://packagist.org/packages/easyswoole/smtp)[ RSS](/packages/easyswoole-smtp/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (7)Dependencies (1)Versions (10)Used By (0)

Smtp
====

[](#smtp)

介绍
--

[](#介绍)

电子邮件是—种用电子手段提供信息交换的通信方式，是互联网应用最广的服务。电子邮件几乎是每个web应用程序不可或缺的，无论是时事通讯还是订单确认。本库采用swoole协程客户端实现了电子邮件的发送

安装
--

[](#安装)

```
composer require easyswoole/smtp
```

用法
--

[](#用法)

### 基础配置

[](#基础配置)

```
$mail = new \EasySwoole\Smtp\Mailer(false);
```

参数:

- `$enableException` 是否启用异常 默认`false`

#### 设置超时

[](#设置超时)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setTimeout(5);
```

#### 设置最大数据包大小

[](#设置最大数据包大小)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setMaxPackage(1024 * 1024 * 2);
```

#### 设置Host

[](#设置host)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setHost("smtp.qq.com");
```

#### 设置Port

[](#设置port)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setPort(465);
```

#### 设置Ssl

[](#设置ssl)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setSsl(true);
```

#### 设置用户名及密码

[](#设置用户名及密码)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setUsername("xxx@qq.com");
$mail->setPassword("xxxxx");
```

#### 设置发件人地址

[](#设置发件人地址)

> 可选方法 默认用户名

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setFrom("xxx@qq.com");
```

参数:

- `$address` 发件人地址
- `$name` 设置昵称 可选参数

#### 设置收件人地址

[](#设置收件人地址)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->addAddress("xxx@qq.com");
```

参数:

- `$address` 收件人地址
- `$name` 设置昵称 可选参数

#### 设置回复地址

[](#设置回复地址)

> 可选方法 默认发件人地址

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$mail->setReplyTo("xxx@qq.com");
```

参数:

- `$address` 收件人地址
- `$name` 设置昵称 可选参数

### 发送

[](#发送)

#### 发送文本

[](#发送文本)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$text = new \EasySwoole\Smtp\Request\Text();
$text->setSubject("Smtp Test Title");
$text->setBody("Smtp Test Body");

// 添加附件 可选
$text->addAttachment(__FILE__,'附件重命名');

// 发送
$mail->send($text);
```

#### 发送Html

[](#发送html)

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
$text = new \EasySwoole\Smtp\Request\Html();
$text->setSubject("Smtp Test Title");
$text->setBody("Smtp Test Body");

// 添加附件 可选
$text->addAttachment(__FILE__,'附件重命名');

// 发送
$mail->send($text);
```

### 注意事项

[](#注意事项)

当开启异常的时候,发送过程中出现问题,将会抛出以下异常:

```
try {
    /** @var \EasySwoole\Smtp\Mailer $mail **/
    $mail->send($text);
}catch (\EasySwoole\Smtp\Exception\Exception $exception) {

}
```

当未开启异常的时候,发送过程中出现问题,将会返回:

```
/** @var \EasySwoole\Smtp\Mailer $mail **/
/** @var \EasySwoole\Smtp\Protocol\Response $response **/
$response = $mail->send($text);
```

### StatusCode

[](#statuscode)

- 0 发送成功
- 101 客户端连接超时
- 102 对端不是smtp协议服务
- 103 客户端接收超时
- 201 向smtp服务标识发送者失败
- 202 smtp服务不支持此验证模式
- 203 用户名出现错误
- 204 密码验证失败
- 205 发件人邮箱地址有误
- 206 收件人邮箱地址有误
- 207 标识邮件数据开始错误
- 208 标识邮件数据结束错误
- 209 退出smtp会话失败

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance9

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~179 days

Recently: every ~156 days

Total

9

Last Release

1215d ago

Major Versions

1.0.x-dev → 2.0.12021-08-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/45c234d5f129ea570e630425636299127647534f0c2cbb073555e2c45d403d6f?d=identicon)[kiss291323003](/maintainers/kiss291323003)

---

Top Contributors

[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (16 commits)")[![RunsTp](https://avatars.githubusercontent.com/u/28254581?v=4)](https://github.com/RunsTp "RunsTp (10 commits)")[![Player626](https://avatars.githubusercontent.com/u/44792981?v=4)](https://github.com/Player626 "Player626 (7 commits)")[![xiaocaigua](https://avatars.githubusercontent.com/u/11884276?v=4)](https://github.com/xiaocaigua "xiaocaigua (4 commits)")[![evalor](https://avatars.githubusercontent.com/u/26944445?v=4)](https://github.com/evalor "evalor (1 commits)")

### Embed Badge

![Health badge](/badges/easyswoole-smtp/health.svg)

```
[![Health](https://phpackages.com/badges/easyswoole-smtp/health.svg)](https://phpackages.com/packages/easyswoole-smtp)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
