https://github.com/phalapi/phpmailer
PhalApi 2.x扩展类库,基于PHPMailer的邮件发送。
https://github.com/phalapi/phpmailer
Last synced: 2 months ago
JSON representation
PhalApi 2.x扩展类库,基于PHPMailer的邮件发送。
- Host: GitHub
- URL: https://github.com/phalapi/phpmailer
- Owner: phalapi
- Created: 2017-09-02T03:46:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-14T01:28:19.000Z (over 5 years ago)
- Last Synced: 2025-04-13T17:08:49.016Z (2 months ago)
- Language: PHP
- Size: 96.7 KB
- Stars: 9
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHPMailer
PhalApi 2.x扩展类库,基于PHPMailer的邮件发送。## 安装和配置
修改项目下的composer.json文件,并添加:
```
"phalapi/phpmailer":"dev-master"
```
然后执行```composer update```,如果PHP版本过低,可使用```composer update --ignore-platform-reqs```。安装成功后,添加以下配置到./config/app.php文件:
```php
'PHPMailer' => array(
'email' => array(
'host' => 'smtp.gmail.com',
'port' => 465,
'Secure' => 'ssl',
'username' => '[email protected]',
'password' => '******',
'from' => '[email protected]',
'fromName' => 'PhalApi团队',
'sign' => '
请不要回复此邮件,谢谢!
-- PhalApi团队敬上 ',
),
),
```## 注册
在./config/di.php文件中,注册邮件服务:
```php
$di->mailer = function() {
return new \PhalApi\PHPMailer\Lite(true);
};
```上面将依赖composer版本的PHPMailer;如果你的PHP版本 <= PHP 5.3,则需要切换到第一版本:
```php
$di->mailer = function() {
return new \PhalApi\PHPMailer\LiteOne(true);
};
```## 使用
如下代码示例:
```php
\PhalApi\DI()->mailer->send('[email protected]', 'Test PHPMailer Lite', 'something here ...');
```稍候将会收到:

如果需要发送邮件给多个邮箱时,可以使用数组,如:
```php
$addresses = array('[email protected]', '[email protected]');
\PhalApi\DI()->mailer->send($addresses, 'Test PHPMailer Lite', 'something here ...');
```## 调试日志
在注册初始化时,传入true可开启调试日志,并可以看到类如:
```
2017-09-03 10:10:58|DEBUG|Succeed to send email|{"addresses":["[email protected]"],"title":"Test PHPMailer Lite"}
```