Email.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\expand\controller;
  3. use app\common\service\HelperService;
  4. use app\common\service\MailService;
  5. use think\Validate;
  6. /**
  7. * 邮件相关
  8. * Class Email
  9. * @package app\expand\controller
  10. */
  11. class Email extends BaseAuth {
  12. private $_Account = null;
  13. public function __construct() {
  14. parent::__construct();
  15. $this->_Account = $this->getKey($this->_apiCode);
  16. //验证是否具有访问这个接口的权限
  17. if (!isset($this->_Account['email_auth'])) {
  18. HelperService::returnJson(['code' => 400, 'msg' => 'email interface unauthorized access', 'data' => []]);
  19. }
  20. }
  21. /**
  22. * 发送邮件
  23. */
  24. public function sendMail() {
  25. $params = $this->_params;
  26. $rule = [
  27. 'send_name|发送者姓名' => 'require',
  28. 'theme_name|主题' => 'require',
  29. 'content|内容' => 'require',
  30. 'reply_mail|回复致xx邮箱' => 'require',
  31. 'to_mail|发送致xx邮箱' => 'require',
  32. ];
  33. $validate = new Validate($rule);
  34. if (!$validate->check($params)) {
  35. HelperService::returnJson(['code' => 400, 'msg' => $validate->getError(), 'data' => $params]);
  36. }
  37. $mailService = new MailService();
  38. $sendName = $params['send_name'];
  39. $themeName = $params['theme_name'];
  40. $content = $params['content'];
  41. $replyMail = $params['reply_mail'];
  42. $toMail = $params['to_mail'];
  43. $result = $mailService->send($sendName,
  44. $themeName,
  45. $content,
  46. $replyMail,
  47. $toMail);
  48. if (!$result) {
  49. HelperService::returnJson(['code' => 400, 'msg' => HelperService::$_httpErr, 'data' => []]);
  50. }
  51. HelperService::returnJson(['code' => 200, 'msg' => 'success', 'data' => []]);
  52. }
  53. }