An open API service indexing awesome lists of open source software.

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的邮件发送。

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 ...');
```

稍候将会收到:

![123123](http://webtools.qiniudn.com/20150411005257_6e6c7a610357cf80e4513557a110d86d)

如果需要发送邮件给多个邮箱时,可以使用数组,如:
```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"}
```