## 一些简单的thinkphp扩展
1. 正则表达式的扩展:
PHP7以上:
```
composer req gherkins/regexpbuilderphp
```
PHP5
```
composer req gherkins/regexpbuilderphp:0.7.*
```
[使用文档](https://github.com/gherkins/regexpbuilderphp/wiki)
[实例](https://github.com/gherkins/regexpbuilderphp)
2.Blade模板引擎扩展
```
composer require terranc/think-blade
```
[GitHub文档](https://github.com/terranc/think-blade)
3.Twig模板引擎扩展
```
composer require yunwuxin/think-twig
```
[GitHub使用文档](https://github.com/yunwuxin/think-twig)
4.Swoole扩展
```
composer require topthink/think-swoole
```
[GitHub使用文档](https://github.com/top-think/think-swoole)
5.phpmailer扩展文件
```
composer require phpmailer/phpmailer
```
或者在composer.json中手动增加一个phpmailer require
```
"require": {
"php": ">=5.4.0",
"topthink/framework": "^5.0",
"topthink/think-image": "^1.0",
"topthink/think-captcha": "^1.0",
"topthink/think-mongo": "^1.0",
"topthink/think-migration": "^1.0",
"topthink/think-angular": "^1.0",
"topthink/think-sae": "^1.0",
"topthink/think-worker": "^1.0",
"topthink/think-queue": "^1.0",
"topthink/think-testing": "^1.0",
"phpmailer/phpmailer": "^5.2"
},
```
然后使用phpmailer类:
```
public function testmailer(){
$mail = new PHPMailer;
dump($mail);
}
```
打印结果:
```
object(PHPMailer)#5 (75) {
["Version"] => string(6) "5.2.16"
["Priority"] => NULL
["CharSet"] => string(10) "iso-8859-1"
["ContentType"] => string(10) "text/plain"
["Encoding"] => string(4) "8bit"
["ErrorInfo"] => string(0) ""
["From"] => string(14) "root@localhost"
["FromName"] => string(9) "Root User"
["Sender"] => string(0) ""
["ReturnPath"] => string(0) ""
["Subject"] => string(0) ""
["Body"] => string(0) ""
["AltBody"] => string(0) ""
["Ical"] => string(0) ""
["MIMEBody":protected] => string(0) ""
["MIMEHeader":protected] => string(0) ""
["mailHeader":protected] => string(0) ""
["WordWrap"] => int(0)
["Mailer"] => string(4) "mail"
["Sendmail"] => string(18) "/usr/sbin/sendmail"
["UseSendmailOptions"] => bool(true)
["PluginDir"] => string(0) ""
["ConfirmReadingTo"] => string(0) ""
["Hostname"] => string(0) ""
["MessageID"] => string(0) ""
["MessageDate"] => string(0) ""
["Host"] => string(9) "localhost"
["Port"] => int(25)
["Helo"] => string(0) ""
["SMTPSecure"] => string(0) ""
```
下一步为了分便使用可以把配置函数写到common.php公共函数文件中如
```
function SendMail($address,$title,$message)
{
$mail=new \PHPMailer;
// 设置PHPMailer使用SMTP服务器发送Email
$mail->IsSMTP();
// 设置邮件的字符编码,若不指定,则为'UTF-8'
$mail->CharSet='UTF-8';
// 添加收件人地址,可以多次使用来添加多个收件人
$mail->AddAddress($address);
// 设置邮件正文
$mail->Body=$message;
// 设置邮件头的From字段。
$mail->From=C('MAIL_ADDRESS');
// 设置发件人名字
$mail->FromName='LilyRecruit';
// 设置邮件标题
$mail->Subject=$title;
// 设置SMTP服务器。
$mail->Host=C('MAIL_SMTP');
// 设置为"需要验证"
$mail->SMTPAuth=true;
// 设置用户名和密码。
$mail->Username=C('MAIL_LOGINNAME');
$mail->Password=C('MAIL_PASSWORD');
// 发送邮件。
return($mail->Send());
}
```
6.thinkphp官方的扩展库
[thinkphp5.1扩展库地址](https://www.kancloud.cn/manual/thinkphp5_1/354126)