123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\expand\controller;
- use app\common\service\HelperService;
- use app\common\service\MailService;
- use think\Validate;
- /**
- * 邮件相关
- * Class Email
- * @package app\expand\controller
- */
- class Email extends BaseAuth {
- private $_Account = null;
- public function __construct() {
- parent::__construct();
- $this->_Account = $this->getKey($this->_apiCode);
- //验证是否具有访问这个接口的权限
- if (!isset($this->_Account['email_auth'])) {
- HelperService::returnJson(['code' => 400, 'msg' => 'email interface unauthorized access', 'data' => []]);
- }
- }
- /**
- * 发送邮件
- */
- public function sendMail() {
- $params = $this->_params;
- $rule = [
- 'send_name|发送者姓名' => 'require',
- 'theme_name|主题' => 'require',
- 'content|内容' => 'require',
- 'reply_mail|回复致xx邮箱' => 'require',
- 'to_mail|发送致xx邮箱' => 'require',
- ];
- $validate = new Validate($rule);
- if (!$validate->check($params)) {
- HelperService::returnJson(['code' => 400, 'msg' => $validate->getError(), 'data' => $params]);
- }
- $mailService = new MailService();
- $sendName = $params['send_name'];
- $themeName = $params['theme_name'];
- $content = $params['content'];
- $replyMail = $params['reply_mail'];
- $toMail = $params['to_mail'];
- $result = $mailService->send($sendName,
- $themeName,
- $content,
- $replyMail,
- $toMail);
- if (!$result) {
- HelperService::returnJson(['code' => 400, 'msg' => HelperService::$_httpErr, 'data' => []]);
- }
- HelperService::returnJson(['code' => 200, 'msg' => 'success', 'data' => []]);
- }
- }
|