控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Ems.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 邮箱类
  13. // +----------------------------------------------------------------------
  14. namespace addons\saiyouems\lib;
  15. class Ems
  16. {
  17. private $_params = [];
  18. protected $error = '';
  19. protected $config = [];
  20. public function __construct($options = [])
  21. {
  22. if ($config = get_addon_config('saiyouems')) {
  23. $this->config = array_merge($this->config, $config);
  24. }
  25. $this->config = array_merge($this->config, is_array($options) ? $options : []);
  26. }
  27. /**
  28. * 立即发送邮件
  29. */
  30. public function send()
  31. {
  32. $this->error = '';
  33. $postArr = array(
  34. "appid" => $this->config['appid'], //用于调用access_token,接口获取授权后的access token
  35. "signature" => $this->config['appkey'], //申请应用时分配的AppSecret
  36. "from" => $this->config['from'], //发件人地址
  37. "to" => $this->_params['email'], //收件人地址
  38. "subject" => $this->_params['subject'], //邮件标题
  39. "text" => $this->_params['text'], //纯文本邮件正文
  40. );
  41. $options = [
  42. CURLOPT_HTTPHEADER => array(
  43. 'Content-Type: application/json; charset=utf-8',
  44. ),
  45. ];
  46. $result = \util\Http::sendRequest('https://api.mysubmail.com/mail/send', json_encode($postArr), 'POST', $options);
  47. if ($result['ret']) {
  48. $res = (array) json_decode($result['msg'], true);
  49. if (isset($res['status']) && $res['status'] == 'success') {
  50. return true;
  51. }
  52. $this->error = isset($res['msg']) ? $res['msg'] : 'InvalidResult';
  53. } else {
  54. $this->error = $result['msg'];
  55. }
  56. return false;
  57. }
  58. /**
  59. * 接收邮箱
  60. */
  61. public function email($email = '')
  62. {
  63. $this->_params['email'] = $email;
  64. return $this;
  65. }
  66. /**
  67. * 邮件标题
  68. */
  69. public function subject($subject = '')
  70. {
  71. $this->_params['subject'] = $subject;
  72. return $this;
  73. }
  74. /**
  75. * 邮件标题
  76. */
  77. public function text($text = '')
  78. {
  79. $this->_params['text'] = $text;
  80. return $this;
  81. }
  82. /**
  83. * 获取错误信息
  84. */
  85. public function getError()
  86. {
  87. return $this->error;
  88. }
  89. }